/* The gateway routine */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *x, *y,*z; int mx,my,nx,ny; /* Check for proper number of arguments. */ if(nrhs!=2) mexErrMsgTxt("Two inputs required."); if(nlhs!=1) mexErrMsgTxt("One output required."); /* Create a pointer to the input y. */ y = mxGetPr(prhs[0]); /* Get the dimensions of the matrix input y. */ my = mxGetM(prhs[0]); ny = mxGetN(prhs[0]); /* Create a pointer to the input x. */ x = mxGetPr(prhs[1]); /* Get the dimensions of the matrix input x. */ mx = mxGetM(prhs[1]); nx = mxGetN(prhs[1]); /* Set the output pointer to the output matrix. plhs[0] = mxCreateDoubleMatrix(my,ny, mxREAL); Create uninitialized matrix for speed up */ plhs[0] = mxCreateDoubleMatrixE(my,ny,mxREAL); /* Create a C pointer to a copy of the output matrix. */ z = mxGetPr(plhs[0]); if (mx==1 && nx==ny){ xtimesyrow(x,y,z,my,ny); } else if (nx==1 && mx==my){ xtimesycol(x,y,z,my,ny); } else if (nx==1 && mx==1){ xtimesy(*x,y,z,my,ny); } else { mexErrMsgTxt("Do not match dim"); } }
/* the gateway function */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *y,*z; double x; size_t mrows,ncols; /* check for proper number of arguments */ /* NOTE: You do not need an else statement when using mexErrMsgIdAndTxt within an if statement, because it will never get to the else statement if mexErrMsgIdAndTxt is executed. (mexErrMsgIdAndTxt breaks you out of the MEX-file) */ if(nrhs!=2) mexErrMsgIdAndTxt( "MATLAB:xtimesy:invalidNumInputs", "Two inputs required."); if(nlhs!=1) mexErrMsgIdAndTxt( "MATLAB:xtimesy:invalidNumOutputs", "One output required."); /* check to make sure the first input argument is a scalar */ if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || mxGetN(prhs[0])*mxGetM(prhs[0])!=1 ) { mexErrMsgIdAndTxt( "MATLAB:xtimesy:xNotScalar", "Input x must be a scalar."); } /* get the scalar input x */ x = mxGetScalar(prhs[0]); /* create a pointer to the input matrix y */ y = mxGetPr(prhs[1]); /* get the dimensions of the matrix input y */ mrows = mxGetM(prhs[1]); ncols = mxGetN(prhs[1]); /* set the output pointer to the output matrix */ plhs[0] = mxCreateDoubleMatrix( (mwSize)mrows, (mwSize)ncols, mxREAL); /* create a C pointer to a copy of the output matrix */ z = mxGetPr(plhs[0]); /* call the C subroutine */ xtimesy(x,y,z,mrows,ncols); }
/* the gateway function */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *yr,*zr,*xr; double *yi,*zi,*xi; size_t mrowsx,mrowsy,ncols; /* check for proper number of arguments */ /* NOTE: You do not need an else statement when using mexErrMsgIdAndTxt within an if statement, because it will never get to the else statement if mexErrMsgIdAndTxt is executed. (mexErrMsgIdAndTxt breaks you out of the MEX-file) */ if(nrhs!=2) mexErrMsgIdAndTxt( "resp_mex:invalidNumInputs", "Two inputs required."); if(nlhs!=1) mexErrMsgIdAndTxt( "resp_mex:invalidNumOutputs", "One output required."); if( !mxIsComplex(prhs[0]) || !mxIsComplex(prhs[1]) ) mexErrMsgIdAndTxt( "MATLAB:convec:inputsNotComplex", "Inputs must be complex.\n"); /* create a pointer to the input matrix x */ xr = mxGetPr(prhs[0]); xi = mxGetPi(prhs[0]); /* get the dimensions of the matrix input x */ mrowsx = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]); if(ncols!=1) mexErrMsgIdAndTxt( "resp_mex:invalidinput", "column vectors required."); /* create a pointer to the input matrix y */ yr = mxGetPr(prhs[1]); yi = mxGetPi(prhs[1]); /* get the dimensions of the matrix input y */ mrowsy = mxGetM(prhs[1]); ncols = mxGetN(prhs[1]); if(ncols!=1) mexErrMsgIdAndTxt( "resp_mex:invalidinput", "column vectors required."); if(mrowsx!=mrowsy) mexErrMsgIdAndTxt( "resp_mex:invalidinput", "x and y must be the same size."); /* set the output pointer to the output matrix */ plhs[0] = mxCreateDoubleMatrix( (mwSize)mrowsx, (mwSize)mrowsy, mxCOMPLEX); /* create a C pointer to a copy of the output matrix */ zr = mxGetPr(plhs[0]); zi = mxGetPi(plhs[0]); /* call the C subroutine */ xtimesy(xr,xi,yr,yi,zr,zi,mrowsx); }