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 commentaires

Jan
Jan le 13 Mai 2011
Please post any datils. It would be very inefficient, if we craete an answer to a question we *guess* at first.
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 le 14 Mai 2011
Show us the code. Then it would be possible to suggest a specific improvement.

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaire

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"};

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by