/*========================================================= * convec.c * example for illustrating how to use pass complex data * from MATLAB to C and back again * * convolves two complex input vectors * * This is a MEX-file for MATLAB. * Copyright 1984-2011 The MathWorks, Inc. *=======================================================*/ #include "mex.h" /* computational subroutine */ void convec( double *xr, double *xi, size_t nx, double *yr, double *yi, size_t ny, double *zr, double *zi) { mwSize i,j; zr[0]=0.0; zi[0]=0.0; /* perform the convolution of the complex vectors */ for(i=0; i 1) mexErrMsgIdAndTxt( "MATLAB:convec:maxlhs", "Too many output arguments."); /*Check that both inputs are row vectors*/ if( mxGetM(prhs[0]) != 1 || mxGetM(prhs[1]) != 1 ) mexErrMsgIdAndTxt( "MATLAB:convec:inputsNotVectors", "Both inputs must be row vectors."); rows = 1; /* Check that both inputs are complex*/ if( !mxIsComplex(prhs[0]) || !mxIsComplex(prhs[1]) ) mexErrMsgIdAndTxt( "MATLAB:convec:inputsNotComplex", "Inputs must be complex.\n"); /* get the length of each input vector */ nx = mxGetN(prhs[0]); ny = mxGetN(prhs[1]); /* get pointers to the 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( (mwSize)rows, (mwSize)cols, mxCOMPLEX); zr = mxGetPr(plhs[0]); zi = mxGetPi(plhs[0]); /* call the C subroutine */ convec(xr, xi, nx, yr, yi, ny, zr, zi); return; }