Traverse cell array of structures of ... in mex

조회 수: 3 (최근 30일)
Peter Cotton
Peter Cotton 2011년 3월 15일
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");
}
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2011년 3월 16일
What do you see when you print mxGetClassName(pm)?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 3월 16일
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
Peter Cotton
Peter Cotton 2011년 3월 17일
Clunk. I sentence myself to two weeks debugging other's code.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Jan
Jan 2011년 3월 16일
I've published two different C-Mex function which access cells and struct fields: frmfield and cstrainbp. Perhaps they help.

Kaustubha Govind
Kaustubha Govind 2011년 3월 15일
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 2011년 3월 16일
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;

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by