Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

create a struct in mexFunction

4 views
Skip to first unread message

yvette

unread,
Dec 18, 2009, 1:01:12 AM12/18/09
to
hi,

in mexFunction(int nlhs,mxArray *plhs[],int nrhs, const mxArray *prhs
[]){}, i tried to create a struct in another struct, but finally i got
a wrong answer. i don't know what is wrong or does Scilab support
creating a struct in another struct in mexFunction?

here is my code:

const char *fn[]={"scalar","matrix","string","struct"};
mxArray *v = mxCreateStructMatrix(1,1,4,fn);
mxSetFieldByNumber(v,0,0,mxCreateDoubleScalar(10));
mxArray *mat = mxCreateDoubleMatrix(1,2,mxREAL);
double *pt = mxGetPr(mat);
pt[0] = 12;
pt[1] = 13;
mxSetFieldByNumber(v,0,1,mat);
mxSetFieldByNumber(v,0,2,mxCreateString("str"));

const char *sfn[]={"one","twol"};
mxArray *st = mxCreateStructMatrix(1,1,2,sfn);
mxSetFieldByNumber(st,0,0,mxCreateDoubleScalar(1));
mxSetFieldByNumber(st,0,1,mxCreateDoubleScalar(2));
mxSetFieldByNumber(v,0,3,st);

plhs[0] = v;

when run, i got the answer like:

res =

scalar: 10
matrix: [12,13]
string: "str"
struct: [1x1 struct]

res.struct =

one: [27x34 unknown]
two: boolean

0 new messages