MATLAB: Traverse cell array of structures of … in mex

cell arraysmexstructures

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");
}

Best Answer

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.