Tim
Tim

Reputation: 99408

Call MATLAB APIs in C/C++

I just heard from somewhere that for numerical computation, "MATLAB does offer some user-friendly APIs. If you call these APIs in your C/C++ code, you can speed up computation dramatically."

But I did not find such information in MATLAB documents like http://www.mathworks.com/support/tech-notes/1600/1622.html and http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/bp_kqh7.html. All I learned from these websites is that MATLAB can be called in C and C++ by Matlab engine or by compiling M-files into libraries by mcc. They don't mention any built-in numerical MATLAB APIs that can be called in C/C++.

Can someone please clarify?

Thanks and regards!

Upvotes: 4

Views: 1702

Answers (3)

Ralphleon
Ralphleon

Reputation: 4108

There could be a few things that quote is referencing, I assume that it is referring to the MATLAB Compiler. So going from MATLAB -> C++ you can use the compiler to build standalone "faster" applications. However, when speed testing the improvement, I've noticed it to be negligible. Honestly, you're probably far better off coding your work in C from the get-go, the code that the compiler generates is spaghetti and non-object oriented. I should also mention that this is an expensive extension to Matlab.

You can use the MCR in your own c++ project as a stand-alone library (details)... but you might get similar results using Numerical Recipes.

Disclaimer: I used this product 2-3 years ago, things could be different now.

Upvotes: 0

devin
devin

Reputation: 6527

It sounds like you're looking for the code generation tools in the embedded matlab toolbox or real time workshop.

Do doc eml and look for a the LMS (least mean square) equalizer demo.

The code generator is quite good, it will give you a make file that will build a static library. It's easy to use with your stand alone C/C++ code.

Upvotes: 0

Adam Goode
Adam Goode

Reputation: 7468

You want the "Engine" routines. This allows you to start up a background MATLAB process from C and execute calculations on it: relevant MATLAB documentation.

It works pretty well, have a look at the examples. I would say the most annoying thing getting it working is marshaling the data between C and MATLAB. But that's always a problem when doing this kind of thing.

Upvotes: 4

Related Questions