How to protect MEX file from empty inputs

조회 수: 1 (최근 30일)
Francesco
Francesco 2013년 10월 21일
답변: dpb 2013년 10월 21일
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

답변 (1개)

dpb
dpb 2013년 10월 21일

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by