00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "mex.h"
00025
00026 void
00027 mexFunction (int nlhs, mxArray* plhs[], int nrhs,
00028 const mxArray* prhs[])
00029 {
00030 int i;
00031 mwIndex j;
00032 mxArray *v;
00033 const char *keys[] = { "this", "that" };
00034
00035 if (nrhs != 1 || ! mxIsStruct (prhs[0]))
00036 mexErrMsgTxt ("expects struct");
00037
00038 for (i = 0; i < mxGetNumberOfFields (prhs[0]); i++)
00039 for (j = 0; j < mxGetNumberOfElements (prhs[0]); j++)
00040 {
00041 mexPrintf ("field %s(%d) = ",
00042 mxGetFieldNameByNumber (prhs[0], i), j);
00043 v = mxGetFieldByNumber (prhs[0], j, i);
00044 mexCallMATLAB (0, 0, 1, &v, "disp");
00045 }
00046
00047 v = mxCreateStructMatrix (2, 2, 2, keys);
00048
00049 mxSetFieldByNumber (v, 0, 0, mxCreateString ("this1"));
00050 mxSetFieldByNumber (v, 0, 1, mxCreateString ("that1"));
00051 mxSetFieldByNumber (v, 1, 0, mxCreateString ("this2"));
00052 mxSetFieldByNumber (v, 1, 1, mxCreateString ("that2"));
00053 mxSetFieldByNumber (v, 2, 0, mxCreateString ("this3"));
00054 mxSetFieldByNumber (v, 2, 1, mxCreateString ("that3"));
00055 mxSetFieldByNumber (v, 3, 0, mxCreateString ("this4"));
00056 mxSetFieldByNumber (v, 3, 1, mxCreateString ("that4"));
00057
00058 if (nlhs)
00059 plhs[0] = v;
00060 }