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

Jan
Jan 2011년 5월 13일
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 2011년 5월 14일
Show us the code. Then it would be possible to suggest a specific improvement.

댓글을 달려면 로그인하십시오.

 채택된 답변

Kaustubha Govind
Kaustubha Govind 2011년 5월 16일
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)에 대해 자세히 알아보기

질문:

2011년 5월 13일

댓글:

2018년 1월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by