Pacific-Design.com

    
Home Index

1. Caltech

2. Matlab

+ Matlab API

+ get size

Caltech / Matlab /

analyze.c


#include 
#include 
#include "mex.h"
/*---------------------------------------------------------------------------*/
/*           mexFunction is the gateway routine for the MEX-file.            */ 
/*---------------------------------------------------------------------------*/
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
  double *x, *y;
  int     mrows, ncols;
  const   mxArray *array_ptr;
  
  /*--- Check for proper number of arguments. ---*/
  if(nrhs != 1)     { mexErrMsgTxt("One input required.");       }
  else if(nlhs > 1) { mexErrMsgTxt("Too many output arguments"); }
  
  /*--- The input must be a noncomplex scalar double. ---*/
  mrows = mxGetM(prhs[0]);  ncols = mxGetN(prhs[0]);

  /*--- Create matrix for the return argument. ---*/
  plhs[0] = mxCreateDoubleMatrix(mrows, ncols, mxREAL);
  
  /*--- Assign pointers to each input and output. ---*/
  x = mxGetPr(prhs[0]);  y = mxGetPr(plhs[0]);

  /*-------------------------------------------------------------------  
     figures out the size of the matrix and copy it into the output
  --------------------------------------------------------------------*/ 
  
  mexPrintf("Total Size: %d\n", mxGetElementSize(prhs[0]) * mxGetM(prhs[0]) * mxGetN(prhs[0]));
  memcpy(y, x, mxGetElementSize(prhs[0]) * mxGetM(prhs[0]) * mxGetN(prhs[0]));
  
}
/*---------------------------------------------------------------------------*/