view examples/mystruct.c @ 14354:55bb8c902a4d

maint: Remove deprecated functions from dev branch for next (3.8) release. * NEWS: Update list of deprecated functions which had duplicates and missing functions * deprecated/module.mk: Remove deprecated m-files from build system. * autocor.m, autocov.m, betai.m, cellidx.m, clg.m, cquad.m, dispatch.m, fstat.m, gammai.m, glpkmex.m, intwarning.m, is_duplicate_entry.m, is_global.m, krylovb.m, perror.m, replot.m, saveimage.m, strerror.m, values.m, weibcdf.m, weibinv.m, weibpdf.m, weibrnd.m: Remove deprecated functions from Mercurial.
author Rik <octave@nomad.inbox5.com>
date Thu, 09 Feb 2012 13:16:39 -0800
parents 6cb30a539481
children be41c30bcb44
line wrap: on
line source

#include "mex.h"

void
mexFunction (int nlhs, mxArray* plhs[], int nrhs, 
             const mxArray* prhs[])
{
  int i;
  mwIndex j;
  mxArray *v;
  const char *keys[] = { "this", "that" };

  if (nrhs != 1 || ! mxIsStruct (prhs[0]))
    mexErrMsgTxt ("expects struct");

  for (i = 0; i < mxGetNumberOfFields (prhs[0]); i++)
    for (j = 0; j < mxGetNumberOfElements (prhs[0]); j++)
      {
        mexPrintf ("field %s(%d) = ", 
                   mxGetFieldNameByNumber (prhs[0], i), j);
        v = mxGetFieldByNumber (prhs[0], j, i);
        mexCallMATLAB (0, 0, 1, &v, "disp");
      }

  v = mxCreateStructMatrix (2, 2, 2, keys);

  mxSetFieldByNumber (v, 0, 0, mxCreateString ("this1"));
  mxSetFieldByNumber (v, 0, 1, mxCreateString ("that1"));
  mxSetFieldByNumber (v, 1, 0, mxCreateString ("this2"));
  mxSetFieldByNumber (v, 1, 1, mxCreateString ("that2"));
  mxSetFieldByNumber (v, 2, 0, mxCreateString ("this3"));
  mxSetFieldByNumber (v, 2, 1, mxCreateString ("that3"));
  mxSetFieldByNumber (v, 3, 0, mxCreateString ("this4"));
  mxSetFieldByNumber (v, 3, 1, mxCreateString ("that4"));

  if (nlhs)
    plhs[0] = v;
}