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 个)
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Deploy to C++ Applications Using mwArray API (C++03) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!