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!

Respuestas (1)

Adam
Adam el 9 de Jun. de 2016
Editada: Adam el 9 de Jun. de 2016
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 comentarios

eey
eey el 10 de Jun. de 2016
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 el 10 de Jun. de 2016
Change the 2nd argument to mxSetField or mxSetFieldByNumber or mxGetFieldByNumber or mxGetField

Iniciar sesión para comentar.

Categorías

Preguntada:

eey
el 9 de Jun. de 2016

Comentada:

el 10 de Jun. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by