mwArray structure index explaination

Hello I am a little bit confused about the documentation of mwArray. Let's say I have structure array like
const char *field_name[] = {"a", "b", "c", "d"};
mwArray structure(2,1,4,field_name);
the question is how can I set value to structure(1).a and structure(2).a respectively? what the index should be in structure.Get() function? Thanks!

답변 (1개)

Adam
Adam 2016년 6월 9일
편집: Adam 2016년 6월 9일

0 개 추천

I tend to use
mxCreateStructMatrix
to create a struct, but I guess your syntax works just as well, judging from the help. Then you can use either of these
mxSetFieldByNumber
mxSetField
to set a field e.g.
const char* axisFieldNames[] = { "x", "y", "z" };
mxArray* labelsStruct = mxCreateStructMatrix( 1, 1, 3, axisFieldNames );
mxSetFieldByNumber( labelsStruct, 0, 0, "someStringForX" );
mxSetFieldByNumber( labelsStruct, 0, 1, "someStringForY" );
mxSetFieldByNumber( labelsStruct, 0, 2, "someStringForZ" );
If you have an actual array of structs as you do then of course you will want to fill in values for indices other than 0 in the 2nd argument. In my code where I took this example from I was just creating a scalar struct.

댓글 수: 2

eey
eey 2016년 6월 10일
Hi, thanks for your reply, but I was talking about mwArray and the question was how to access different element if I have a structure array and set values for the same field in different elements.
Adam
Adam 2016년 6월 10일
Change the 2nd argument to mxSetField or mxSetFieldByNumber or mxGetFieldByNumber or mxGetField

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

카테고리

도움말 센터File Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기

질문:

eey
2016년 6월 9일

댓글:

2016년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by