7019
|
1 /* |
|
2 |
|
3 Copyright (C) 2006, 2007 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
7081
|
7 Octave is free software; you can redistribute it and/or |
|
8 modify it under the terms of the GNU General Public License |
|
9 as published by the Free Software Foundation; either |
|
10 version 3 of the License, or (at your option) any later |
|
11 version. |
7019
|
12 |
7081
|
13 Octave is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty |
|
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16 See the GNU General Public License for more details. |
7019
|
17 |
7081
|
18 You should have received a copy of the GNU General Public |
|
19 License along with Octave; see the file COPYING. If not, |
|
20 see <http://www.gnu.org/licenses/>. |
7019
|
21 |
|
22 */ |
|
23 |
5864
|
24 #include "mex.h" |
|
25 |
|
26 void |
7081
|
27 mexFunction (int nlhs, mxArray* plhs[], int nrhs, |
|
28 const mxArray* prhs[]) |
5864
|
29 { |
6686
|
30 int i; |
|
31 mwIndex j; |
5864
|
32 mxArray *v; |
|
33 const char *keys[] = { "this", "that" }; |
|
34 |
|
35 if (nrhs != 1 || ! mxIsStruct (prhs[0])) |
|
36 mexErrMsgTxt ("expects struct"); |
|
37 |
|
38 for (i = 0; i < mxGetNumberOfFields (prhs[0]); i++) |
6581
|
39 for (j = 0; j < mxGetNumberOfElements (prhs[0]); j++) |
5864
|
40 { |
6580
|
41 mexPrintf ("field %s(%d) = ", |
|
42 mxGetFieldNameByNumber (prhs[0], i), j); |
|
43 v = mxGetFieldByNumber (prhs[0], j, i); |
6581
|
44 mexCallMATLAB (0, 0, 1, &v, "disp"); |
5864
|
45 } |
|
46 |
|
47 v = mxCreateStructMatrix (2, 2, 2, keys); |
|
48 |
|
49 mxSetFieldByNumber (v, 0, 0, mxCreateString ("this1")); |
|
50 mxSetFieldByNumber (v, 0, 1, mxCreateString ("that1")); |
|
51 mxSetFieldByNumber (v, 1, 0, mxCreateString ("this2")); |
|
52 mxSetFieldByNumber (v, 1, 1, mxCreateString ("that2")); |
|
53 mxSetFieldByNumber (v, 2, 0, mxCreateString ("this3")); |
|
54 mxSetFieldByNumber (v, 2, 1, mxCreateString ("that3")); |
|
55 mxSetFieldByNumber (v, 3, 0, mxCreateString ("this4")); |
|
56 mxSetFieldByNumber (v, 3, 1, mxCreateString ("that4")); |
|
57 |
|
58 if (nlhs) |
|
59 plhs[0] = v; |
|
60 } |