Skip to Main Content Skip to Search
Product Documentation

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)
y=x+2;
end

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
y=x+2;
end

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:

myfcn(x)
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS