Traverse cell array of structures of ... in mex

Does anyone have a nice .mex example where we pass in a cell array of struct, and interrogate fields in each structure?
This mex newby is baffled as to why mxIsStruct returns false when the following is passed a cell array of struct:
void blah(mxArray* X)
mxArray* pm;
mwIndex i;
i = 1;
pm = mxGetCell(X,i);
if (~mxIsStruct(pm)) {
mexErrMsgTxt("Not a structure");
}

 Réponse acceptée

Jan
Jan le 16 Mar 2011
You are talking about C, not Matlab. In C the NOT operator is "!", not "~".
if (~mxIsStruct(pm)) % Bad
if (!mxIsStruct(pm)) % Good
The tilde ~ is the bitwise complement in C.

1 commentaire

Peter Cotton
Peter Cotton le 17 Mar 2011
Clunk. I sentence myself to two weeks debugging other's code.

Connectez-vous pour commenter.

Plus de réponses (3)

Jan
Jan le 16 Mar 2011

1 vote

I've published two different C-Mex function which access cells and struct fields: frmfield and cstrainbp. Perhaps they help.
Kaustubha Govind
Kaustubha Govind le 15 Mar 2011

0 votes

The example phonebook.c accepts an array of structs and returns a cell array - this should serve as a good starting point.
James Tursa
James Tursa le 16 Mar 2011
C is 0-based indexing. You have this in your code:
i = 1;
Are you sure you have two elements in X? Or did you mean:
i = 0;

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by