How to transform MATLAB code into C++ code.

by raulzito234

When you compile matlab code using mcc (by default or when using the -m option), you get an executable. So from your C++ file, you can call the matlab executable with the C/C++ command exec.

If you use the -l option (using mcc), you get a shared library, and header. For instance if you type (in matlab):

mcc -l test.m -W cpplib:test.h

This should produce a shared library test.lib or, and a header test.h

In test.h you should have line similar to that:

bool MW_CALL_CONV mlxTest(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);

You can call your matlab function using that.

In addition you have to add both shared libraries and headers in you msvc project.