Filter löschen
Filter löschen

How to protect MEX file from empty inputs

5 Ansichten (letzte 30 Tage)
Francesco
Francesco am 21 Okt. 2013
Beantwortet: dpb am 21 Okt. 2013
Hello,
I have a function of the form:
void nodal_connectivity(double *links, int maxconnections,
int size_rn, int size_links,
double *node_connectivity);
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *links;
double *node_connectivity;
int maxconnections,size_rn,size_links;
if (nrhs!=4) mexErrMsgTxt("4 inputs required: links and maxconnections, size_rn, size_links!");
if (nlhs!=1) mexErrMsgTxt("Only one output given, node_connectivity");
links=mxGetPr(prhs[0]);
maxconnections=mxGetScalar(prhs[1]);
size_rn=mxGetScalar(prhs[2]);
size_links=mxGetScalar(prhs[3]);
plhs[0]=mxCreateDoubleMatrix(size_rn*maxconnections,1,mxREAL);
node_connectivity=mxGetPr(plhs[0]);
nodal_connectivity(links,maxconnections,size_rn,size_links,node_connectivity);
}
When I call the function, I would like to protect Matlab if the "links" array is empty. This may occur in my Matlab program. I know that I can simply put a not(isempty(links)) condition prior to execution of the MEX file, but to make it a bit more robust (i.e. in case I forget), is there a test in mxFunction that tests for empty inputs and if so, exits with a given return value for example?
Thank you!
F

Antworten (1)

dpb
dpb am 21 Okt. 2013
doc mxIsEmpty

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by