Difference between MATLAB mex API to MATLAB engine API

2 views (last 30 days)
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):
#include <engine.h>
#include <matrix.h>
#include <mex.h>
#include <mat.h>
int main()
{
Engine *MATLAB;
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!!
return 0;
}
Now, when writing the equivalent code with mex API, everything works perfectly as follows:
1: Am running the next MATLAB's script:
mex getMex.cpp;%compile getMex.cpp (with VS 2010 Ultimate), see code below
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
LineWidth = getMex(h);% OK!! LineWidth = 2.5
the getMex.cpp source file:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
//some input/output checks here
mxArray *p = mxGetProperty(prhs[0],0,"LineWidth"); //OK!!! - not NULL
double *p2h=mxGetPr(p);//OK!!! *p2h = 2.5
plhs[0] = 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?

Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!