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