When creating MATLAB® functions for use in engine applications, it is good practice to debug the functions in MATLAB before calling them through the engine library functions.
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)