How can I access nested MATLAB structure fields in my MEX program?

I have created a nested structure in MATLAB:
substruct.a = 1
substruct.b = 2
s.c = 3
s.sub = substruct
Now I would like to write a MEX program that can access certain levels of depth into this structure. I would like to access these fields in my MEX-file.

 Respuesta aceptada

The following code fragment demonstrates how to extract a substructure and then extract a field from that substructure:
substructure_field_num = mxGetFieldNumber(pa, "substructure");
mxArray *sub = mxGetFieldByNumber(pa, index, substructure_field_num);
field_num = mxGetFieldNumber(sub, "my_field");
mxArray *myField = mxGetFieldByNumber(sub, index, field_num);
For more information on using structures in general, see the documentation for mxGetFieldByNumber and the related PHONEBOOK.C example. You can use the following command in MATLAB to access the documentation:
doc mxGetFieldByNumber

Más respuestas (0)

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.

Productos

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by