5

To call MATLAB code in C or C++, how do you choose between using the MATLAB engine and using the MATLAB Compiler mcc to create C or C++ shared libraries from your MATLAB code? What are their pros and cons? For the second method, see http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f2-9676.html

Are there other ways to call MATLAB from C or C++?

Amro
  • 123,847
  • 25
  • 243
  • 454
Tim
  • 1
  • 141
  • 372
  • 590
  • 1
    Might want to check out http://stackoverflow.com/questions/1071778/data-streaming-in-matlab-with-input-data-coming-in-from-a-c-executable/1074038#1074038 – Jacob Oct 16 '09 at 19:18
  • Thanks but that is not what I want. I am not talking about calling C or C++ from Matlab by mex, but mcc-compiling matlab code into library which can later be called in C or C++. – Tim Oct 16 '09 at 21:29
  • 1
    I don't know the full answer, but look at the install requirements for execution. Invoking the MATLAB engine definitely requires having MATLAB installed on the machine. Does that hold true for when you're just using shared libraries? – Kennet Belenky Oct 16 '09 at 21:47
  • If I am not wrong, the answer could be false if the required Matlab internal shared libraries are deployed as the help document says. – Tim Oct 16 '09 at 22:28

1 Answers1

2

If the computation is linear and long, I would use mcc to compile the code. It is as if MATLAB was simply another library with numerical routines in it to be linked into your program.

If I wanted to provide interaction with MATLAB in my program, where the user could specify any of a large number of statements that would be impossible or merely tedious to code individually, then I would use the MATLAB engine. It is as if I wanted to run MATLAB without the Mathworks' UI.

I have never bothered with opening the MATLAB engine outside of a test.

Mark Ruzon
  • 3,297
  • 2
  • 15
  • 11