Matlab has double values ββby default. You can easily use them in your mex function, as in the following example based on your code snippet. I made myFunction, which performs a demo algorithm. Instead of returning a data type, I make it a void function and pass it a pointer to the output so that it can fill it.,.
/*************************************************************************/ /* Header(s) */ /*************************************************************************/ #include "mex.h" #include "math.h" /*************************************************************************/ /*the fabled myFunction */ /*************************************************************************/ void myFunction(unsigned int N, unsigned int siz, double* output) { int sign = 1; for(int ii=0; ii<siz; ++ii) { output[ii] = (double)(ii * sign + N); sign *= -1; } } /*************************************************************************/ /* Gateway function and error checking */ /*************************************************************************/ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* variable declarations */ unsigned int siz; double N; /* check the number of input and output parameters */ if(nrhs!=1) mexErrMsgTxt("One input arg expected"); if(nlhs > 1) mexErrMsgTxt("Too many outputs"); N = mxGetScalar(prhs[0]); /* assign a pointer to the output */ siz= 2*ceil(log(1.0*N)/log(2.0)-0.5)+1; plhs[0] = mxCreateDoubleMatrix(1,siz, mxREAL); myFunction(N, siz, mxGetPr( plhs[0]) ); }
source share