Click here to Skip to main content
15,884,007 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to use matlab function in visual c++
anybudy have any idea
Posted

 
Share this answer
 
Comments
Albert Holguin 2-Nov-11 14:10pm    
Be advised that calling the engine from your code means you're still bound to Matlab directly... in another words, you have to install (and therefore distribute) the Matlab engine for your application to work, given the cost of Matlab, I can't imagine this is by no means free.
Maximilien 2-Nov-11 14:13pm    
Yeah, just figured that out (engine vs. DLL/lib code)
In any cases, if you want to call mathlab functions you will still need to link to mathlab dll/libs, and you will need to already have them , and if you ship to customers, you will need to ship mathlab dll/lib to clients (royalties, one-time fees,...)
Albert Holguin 2-Nov-11 14:23pm    
Don't know the pricing structure of using their DLLs after you've compiled the source, but installing the engine is not the same as distributing the DLLs you would need if you compiled the source. Installing the engine means the computer has access to the entire heart of Matlab (minus the IDE). I believe if you compile the code you just need some interfacing DLLs. Either way, Matlab is not cheap so pricing is always a consideration. That's why I also brought up the option of just using Matlab to develop/learn the algorithms then developing your own routines.
pranav_30 2-Nov-11 14:25pm    
i am able to call matlab function using.
Engine *ep;
ep = engOpen("");
engEvalString(ep,"x = (1:1:10);" );
engEvalString(ep, "y = x.^2;");
engEvalString(ep, "plot(x,y);" );
ep = engOpen("");

now tel me if i make executable of my project and give to the client. then client pc need matlab installed for runnig the project
Albert Holguin 2-Nov-11 14:33pm    
It needs the "engine"... which is what Matlab calls its internal mathematical engine (as opposed to other IDE components/toolboxes/simulink/etc.). So you would have to redistribute that... so make sure that you're doing it legally.
Matlab offers a compiler[^] (probably at an extra charge, not sure though) to compile their source into a shared library. Once compiled, you should be able to access the code as a dll or a static lib (see compiler specs for what they support).

Alternatively, you can code your own routines based on what you've learned. This approach will probably allow you to optimize your code and run it faster than just using what the Matlab compiler puts out and is generally a better approach for a commercial product.
 
Share this answer
 
Comments
pranav_30 3-Nov-11 1:48am    
hey bro thanks now i am able to create dll n some cpp file and object file using deployment tool... can u tel me how can i use this dll file to my visual c++ project..
pranav_30 3-Nov-11 2:42am    
i m getting following error


1>sharedcpp.obj : error LNK2001: unresolved external symbol ___MCC_sharedcpp_component_data
1>D:\pranav_study\final_work\matlab_demo\Debug\matlab_demo.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://d:\pranav_study\final_work\matlab_demo\matlab_demo\Debug\BuildLog.htm"
1>matlab_demo - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900