Effacer les filtres
Effacer les filtres

How to protect MEX file from empty inputs

5 vues (au cours des 30 derniers jours)
Francesco
Francesco le 21 Oct 2013
Réponse apportée : dpb le 21 Oct 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

Réponses (1)

dpb
dpb le 21 Oct 2013

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by