annotate examples/mystruct.c @ 7334:274d9642ac10 release-3-0-0

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