Lazer
Lazer

Reputation: 94800

How to call MATLAB code from C?

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?

Upvotes: 12

Views: 14030

Answers (3)

Pete Kirkham
Pete Kirkham

Reputation: 49311

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

Upvotes: 17

user3029135
user3029135

Reputation:

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

Upvotes: 0

Sam Roberts
Sam Roberts

Reputation: 24127

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.

Upvotes: 10

Related Questions