How to call MATLAB code from C?

為{幸葍}努か 提交于 2019-11-26 07:42:46

问题


I have some code that plots triangles in MATLAB.

I need to be able to somehow execute this code from my C program which generates these points.

Is that possible? How can it be done?

Just a thought: Can I somehow embed MATLAB code in C, so that it can compile on a C compiler?


回答1:


The Mathworks site has full details; a demo video of calling the Matlab engine from C, and also the Matlab to C Compiler.




回答2:


As mentioned previously by answerers, you can call a live copy of MATLAB from C via the MATLAB Engine interface.

If the end-product needs to be used where there is no live copy of MATLAB, you can deploy the application using MATLAB Compiler. However, MATLAB Compiler does not, as another answer has suggested, convert MATLAB programs into C code (and hasn't done for a few versions now). Instead, it archives and encrypts your MATLAB program, and packages it into an executable or shared library that executes against the MATLAB Compiler Runtime (shareable royalty-free). The executable or shared library can then be called from C.

Alternatively you could go the other way around, and call your C code from MATLAB, using either loadlibrary or MATLAB's MEX interface.

Update: As of release R2011a, you can also use MATLAB Coder to generate C code directly from a subset of the MATLAB language.




回答3:


Look at this presentation about integrating MATLAB Algorithms in C or C++ Applications http://www.mathworks.com/videos/integrating-matlab-algorithms-in-c-or-c-applications-86431.html



来源:https://stackoverflow.com/questions/1513583/how-to-call-matlab-code-from-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!