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 Comments

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.
Show us the code. Then it would be possible to suggest a specific improvement.

Sign in to comment.

 Accepted Answer

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 Comment

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

Sign in to comment.

More Answers (0)

Categories

Asked:

on 13 May 2011

Commented:

on 19 Jan 2018

Community Treasure Hunt

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

Start Hunting!