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 个评论

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.

请先登录,再进行评论。

 采纳的回答

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by