How to create a structure inside structure in mex file.

[EDIT: 20110512 23:27 CDT - clarify - WDR]
I have a binary tree from which I want to create a structure.

3 comentarios

Jan
Jan el 13 de Mayo de 2011
Please post any datils. It would be very inefficient, if we craete an answer to a question we *guess* at first.
Himanshu
Himanshu el 14 de Mayo de 2011
i have text file consisting of signal names and data which i am reading and creating a tree.The signal list comprise of signals in dot notation, So i have to read the text file and and create the binary tree from which i want to create the structure. I am able to create structure with using mexArray function but when i try to create a structure for an existing field inside the existing structure i am not able to do.
Jan
Jan el 14 de Mayo de 2011
Show us the code. Then it would be possible to suggest a specific improvement.

Iniciar sesión para comentar.

 Respuesta aceptada

I think what you intend to construct is a nested structure. Try something like:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
char* level1_fnames[] = {"level1_a", "level1_b"};
char* level2_fnames[] = {"level2_a1", "level2_a2"};
mxArray* level2_struct;
plhs[0] = mxCreateStructMatrix(1, 1, 2, level1_fnames);
level2_struct = mxCreateStructMatrix(1, 1, 2, level2_fnames);
mxSetField(plhs[0], 0, "level1_a", level2_struct);
}

1 comentario

This worked for me after I changed two lines to:
const char* level1_fnames[] = {"level1_a", "level1_b"};
const char* level2_fnames[] = {"level2_a1", "level2_a2"};

Iniciar sesión para comentar.

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.

Preguntada:

el 13 de Mayo de 2011

Comentada:

el 19 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by