mxFunctions: Nested Structures within Structure Arrays

mxFunctions: Nested Structures within Structure Arrays

Post by Warren Bla » Thu, 09 Sep 2004 08:45:57


Hello,

I would like to use the C MX Functions to create matlab data; I want
a struct array a la the following:

struct_name(1).field_name_a.subfield_a_1 = 1;
struct_name(1).field_name_a.subfield_a_2 = 'some_char_data';
struct_name(1).field_name_b.subfield_b_1 = 30.00;
struct_name(1).field_name_b.subfield_b_2 = {'some_cell_data'}

struct_name(2).field_name_a.subfield_a_1 = 2;
struct_name(2).field_name_a.subfield_a_2 = 'some_more_char_data';
struct_name(2).field_name_b.subfield_b_1 = 30.00;
struct_name(2).field_name_b.subfield_b_2 = {'some_more_cell_data'}

Does anyone know a way to accomplish this? I will appreciate any
help! Thanks, WB
 
 
 

mxFunctions: Nested Structures within Structure Arrays

Post by AJ "no z"J » Fri, 10 Sep 2004 01:07:45


Sure... this is pretty easy, actually.
First, you need to create a structure using mxCreateStructMatrix(). This
defines the shape, and the field names, but not the actual data.
Second, create an array that you want to place in the structure, for example
mxCreateCellMatrix(), or mxCreateDoubleMatrix(). (I think those names are
right.)
Third, associate those arrays as data in the structure, using mxSetField().
Repeat Second and Thord steps until your structure is completely populated.
These is no need to populated 'empty' fields.

Cells arrays are created in much the same way.
This procedure can be performed recursively, to created nested constructs.
The 'cstruct' package on the File Exchange is a (perhaps confusing) example
of a recursive implemention of such.
HTH,
Aj

 
 
 

mxFunctions: Nested Structures within Structure Arrays

Post by Warren Bla » Fri, 10 Sep 2004 01:17:15

Thank you much AJ. Had given this a shot last night and it appears to
work well. I appreciate the response!

Regards,
WB