Reputation: 295
I have a C++ program in Visual Studio that records data and saves it into a file. I want to do some Matlab analysis reading from that file and save the results in a separate one. Then, my C++ program keeps going.
Is there any way to do this automatically coding the call in C++ when Matlab is open in the same computer?
Thanks in advance!
Upvotes: 8
Views: 7986
Reputation: 2385
There are many ways to call MATLAB from C++ depending on your needs. Many similar questions have been asked here in the past and I will refer to those and as well give you a solution as your requirement seems to be different.
mex
functions described here, here, here and the actual MATLAB documentationYour problem falls under the third category. So you need to either call MATLAB engine (See Tal Darom's answer) or write a shell script. I will explain the latter. Lets write a shell script called matlab_script.sh
:
#/bin/sh
matlab -nodisplay -nojvm -nosplash < your_matlab_file.m
then in your C++ code do this:
system("matlab_script.sh");
You need matlab_script.sh
to be executable. Under linux you normally do chmod +x matlab_script.sh
Upvotes: 8
Reputation: 76785
You can make use of the Matlab Compiler SDK, which turns your matlab code into a standalone program or library.
You can then call this libary from your C++ code, and the end user won't even need to have Matlab installed (just the Compiler Runtime, which you can deploy "royalty-free"), see this web page for what you can do with it.
Upvotes: 1
Reputation: 1409
You can start a matlab engine from within a program, and run matlab scripts using matlab engine API.
see documentation at: http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html
Upvotes: 1