User`s manual

2 Creating C Language MEX-Files
2-22
Below is the gateway routine that calls this complex convolution.
/* The gateway routine. */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *xr, *xi, *yr, *yi, *zr, *zi;
int rows, cols, nx, ny;
/* Check for the proper number of arguments. */
if(nrhs != 2)
mexErrMsgTxt("Two inputs required.");
if(nlhs > 1)
mexErrMsgTxt("Too many output arguments.");
/* Check that both inputs are row vectors. */
if(mxGetM(prhs[0]) != 1 || mxGetM(prhs[1]) != 1 )
mexErrMsgTxt("Both inputs must be row vectors.");
rows = 1;
/* Check that both inputs are complex. */
if(!mxIsComplex(prhs[0]) || !mxIsComplex(prhs[1]) )
mexErrMsgTxt("Inputs must be complex.\n");
/* Get the length of each input vector. */
nx = mxGetN(prhs[0]);
ny = mxGetN(prhs[1]);
/* Get pointers to real and imaginary parts of the inputs. */
xr = mxGetPr(prhs[0]);
xi = mxGetPi(prhs[0]);
yr = mxGetPr(prhs[1]);
yi = mxGetPi(prhs[1]);
/* Create a new array and set the output pointer to it. */
cols = nx + ny - 1;
plhs[0] = mxCreateDoubleMatrix(rows, cols, mxCOMPLEX);
zr = mxGetPr(plhs[0]);
zi = mxGetPi(plhs[0]);