doc mxIsEmpty
How to protect MEX file from empty inputs
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!