1

For a project I am working on I'm preparing data in MATLAB, then running the data through a separate external application (written in C++) named Model v2.exe, then performing further analysis with the output in MATLAB. I'm trying to create an M-file which does all of this, but I am struggling to get the C++ program to launch from my MATLAB code.

How can I launch an external application from within my MATLAB code?

1
  • Just guessing: if the external C++ application is yours as well, you could also build it as a shared library and call it directly from matlab. This would have much less overhead than issuing a system() call. Commented Mar 20, 2014 at 8:59

1 Answer 1

1

You can either make use of the ! operator, or the system() command.

First, rename you application to something that has no spaces in the name, like modelv2.exe. Next, either make sure it is in the system path, as defined by your system environment variables, or generate a full path to it (eg: C:\Users\Phil\Desktop\modelv2.exe).

You can call an executable program from the command line using the exclamation point or the system command:

!modelv2

or:

!C:\Users\Phil\Desktop\modelv2.exe

will cause Windows to execute the program hello.exe if there is such a file in the current directory or on the system path. Alternatively:

system('modelv2');

or

system('C:\Users\Phil\Desktop\modelv2.exe');

will do the same thing.

References


  1. "MATLAB Central - call and run an external program in matlab under windows", Accessed 2014-03-19, <http://www.mathworks.com/matlabcentral/answers/11568-call-and-run-an-external-program-in-matlab-under-windows>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Dogbert, great help.
What happens if the external program needs an input parameter? How is it done, then?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.