Documentation Center

  • Trial Software
  • Product Updates

Troubleshooting Engine Applications

Can't Start MATLAB Engine Message

If you have multiple versions of MATLAB® installed on your system, the version you use to build your engine applications must be the first listed in your system Path environment variable. Otherwise, MATLAB displays Can't start MATLAB engine. For information about setting the Path variable, see Setting Run-Time Library Path on Windows or Setting Run-Time Library Path on Linux and Macintosh.

On Windows® operating systems, you also need to register MATLAB as a COM server. If you have multiple versions of MATLAB, the version you are using must be the registered version. For instructions, see Registering MATLAB Software as a COM Server.

Debugging MATLAB Functions Used in Engine Applications

When creating MATLAB functions for use in engine applications, it is good practice to debug the functions in MATLAB before calling them via the engine interface.

Although you cannot use the MATLAB Editor/Debugger from an engine application, you can use the MATLAB workspace to examine variables passed to MATLAB. For example, you have the following MATLAB function:

function y=myfcn(x)

Your engine application calls myfcn with your variable mycmxarray, as shown in the following code:

engPutVariable(ep, "aVar", mycmxarray);
engEvalString(ep, "result = myfcn(aVar)");
mycmxarrayResult = engGetVariable(ep,"result");

If you do not get the expected result, you can examine two possibilities: if the input, mycmxarray, is incorrect, or if the MATLAB function is incorrect.

To examine the input to myfcn, first modify the function to save the MATLAB workspace to the file debugmyfcn.mat.

function y=myfcn(x)
save debugmyfcn.mat

Execute your engine application, then start MATLAB and load debugmyfcn.mat.

load debugmyfcn.mat
whos x

Variable x contains the value from mycmxarray. If x is not what you expect, debug your engine code. If x is correct, debug the MATLAB function. To debug myfcn, open the function in the MATLAB Editor/Debugger, and then call the function from the MATLAB command line:

Was this topic helpful?