Mercurial > hg > octave-lyh
comparison examples/mystruct.c @ 5864:e884ab4f29ee
[project @ 2006-06-22 00:57:27 by jwe]
author | jwe |
---|---|
date | Thu, 22 Jun 2006 00:57:28 +0000 |
parents | |
children | d2bb3b8a8d20 |
comparison
equal
deleted
inserted
replaced
5863:4c16f3104aa5 | 5864:e884ab4f29ee |
---|---|
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 } |