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
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 个评论

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.
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