I am having diffculties in getting (and, thus, setting) graphic objects' properties via matlab's engine API: I'm always getting NULL pointer in the following code (Am using R2015b on windows 8.1):
if (!(MATLAB = engOpen(NULL)))
//exit failure etc.
engEvalString(MATLAB, "clearvars;close all;x=linspace(-pi,pi);figure;h=plot(x,sin(x),'o-b','LineWidth',2.5);");//OK!! got the plot on a new figure
const mxArray *ph = engGetVariable(MATLAB, "h");//OK!!
const char *cname = mxGetClassName(ph);// OK!!!: got cname = matlab.graphics.chart.primitive.Line
size_t ind = 0;
const char *Prop = "LineWidth";
mxArray *p = mxGetProperty(ph,ind,Prop);//bummer !!! - p is always NULL!!
Now, when writing the equivalent code with mex API, everything works perfectly as follows:
1: Am running the next MATLAB's script:
LineWidth = getMex(h);
the getMex.cpp source file:
void mexFunction(int nlhs, mxArray *plhs, int nrhs,
const mxArray *prhs)
//some input/output checks here
mxArray *p = mxGetProperty(prhs,0,"LineWidth"); //OK!!! - not NULL
double *p2h=mxGetPr(p);//OK!!! *p2h = 2.5
plhs = p;
While debugging both the mex code and the engine code in VS 2010 I saw that the same dlls were loaded exactly.
What is the problem with my engine API code?
What am I missing here?