#include "mex.h" /* * timestwo.c - example found in API guide * * Computational function that takes a scalar and doubles it. * * This is a MEX-file for MATLAB. * Copyright 1984-2011 The MathWorks, Inc. */ void timestwo(double y[], double x[]) { y[0] = 2.0*x[0]; } void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *x,*y; size_t mrows,ncols; /* Check for proper number of arguments. */ if(nrhs!=1) { mexErrMsgIdAndTxt( "MATLAB:timestwo:invalidNumInputs", "One input required."); } else if(nlhs>1) { mexErrMsgIdAndTxt( "MATLAB:timestwo:maxlhs", "Too many output arguments."); } /* The input must be a noncomplex scalar double.*/ mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]); if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrows==1 && ncols==1) ) { mexErrMsgIdAndTxt( "MATLAB:timestwo:inputNotRealScalarDouble", "Input must be a noncomplex scalar double."); } /* Create matrix for the return argument. */ plhs[0] = mxCreateDoubleMatrix((mwSize)mrows, (mwSize)ncols, mxREAL); /* Assign pointers to each input and output. */ x = mxGetPr(prhs[0]); y = mxGetPr(plhs[0]); /* Call the timestwo subroutine. */ timestwo(y,x); }