5864
|
1 #include "mex.h" |
|
2 |
|
3 void |
7081
|
4 mexFunction (int nlhs, mxArray* plhs[], int nrhs, |
|
5 const mxArray* prhs[]) |
5864
|
6 { |
6686
|
7 int i; |
|
8 mwIndex j; |
5864
|
9 mxArray *v; |
|
10 const char *keys[] = { "this", "that" }; |
|
11 |
|
12 if (nrhs != 1 || ! mxIsStruct (prhs[0])) |
|
13 mexErrMsgTxt ("expects struct"); |
|
14 |
|
15 for (i = 0; i < mxGetNumberOfFields (prhs[0]); i++) |
6581
|
16 for (j = 0; j < mxGetNumberOfElements (prhs[0]); j++) |
5864
|
17 { |
6580
|
18 mexPrintf ("field %s(%d) = ", |
|
19 mxGetFieldNameByNumber (prhs[0], i), j); |
|
20 v = mxGetFieldByNumber (prhs[0], j, i); |
6581
|
21 mexCallMATLAB (0, 0, 1, &v, "disp"); |
5864
|
22 } |
|
23 |
|
24 v = mxCreateStructMatrix (2, 2, 2, keys); |
|
25 |
|
26 mxSetFieldByNumber (v, 0, 0, mxCreateString ("this1")); |
|
27 mxSetFieldByNumber (v, 0, 1, mxCreateString ("that1")); |
|
28 mxSetFieldByNumber (v, 1, 0, mxCreateString ("this2")); |
|
29 mxSetFieldByNumber (v, 1, 1, mxCreateString ("that2")); |
|
30 mxSetFieldByNumber (v, 2, 0, mxCreateString ("this3")); |
|
31 mxSetFieldByNumber (v, 2, 1, mxCreateString ("that3")); |
|
32 mxSetFieldByNumber (v, 3, 0, mxCreateString ("this4")); |
|
33 mxSetFieldByNumber (v, 3, 1, mxCreateString ("that4")); |
|
34 |
|
35 if (nlhs) |
|
36 plhs[0] = v; |
|
37 } |