필터 지우기
필터 지우기

How to build a mex return structure?

조회 수: 9 (최근 30일)
Jeff
Jeff 2016년 6월 29일
댓글: Jeff 2016년 7월 22일
I am unable to figure out how to build and attach matrices to the structure I have being returned
mwSize dims[2] = {1,NumChans};
plhs[0] = mxCreateStructArray(2, dims, NUMBER_OF_FIELDS, field_names);
I want to place matrices in one of the fields where I'll have a different one for each structure element. I can't seem to find any examples how best to do this, would there possibly be such an example?
Thanks

채택된 답변

Adam
Adam 2016년 6월 29일
편집: Adam 2016년 6월 29일
You can create an mxArray as you would anywhere else, e.g.
mxArray* myArray = mxCreateDoubleMatrix( 3, 4, mxREAL );
double* dataPtr = mxGetPr( myArray );
// Some code here to fill up myArray however you want using dataPtr
mxSetField( plhs[0], 0, field_names{1}, myArray ); // Assign matrix to first field name of 1st structure in array
mxSetField( plhs[1], 1, field_names{1}, myOtherArray ); // Assign matrix to first field name of 2nd structure in array
etc
with myOtherArray created by whatever method you choose also.
  댓글 수: 8
James Tursa
James Tursa 2016년 6월 29일
편집: James Tursa 2016년 6월 29일
Can you post your current code or pseudo-code with comments as to what you want at the end of the process? I.e., "I want an X-element structure with fields named AAA, BBB, etc and each field will contain ETC ETC".
I am not really sure where you are getting stuck. Once you know how many elements you want (NumChans?), you loop through them to set the field values. Looks like you are doing that already, so I don't see where you are having problems with this.
Jeff
Jeff 2016년 7월 22일
I neglected to make it an array of pointers, this works fine
mxArray **Data = new mxArray*[ NumChans ];

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

추가 답변 (0개)

카테고리

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