How do I read an input array of type double in mex?
Show older comments
I am creating an Array of type double using arr = rand(5,1) I simply want to be able to pass into into my mex function and read the values
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *A;
const mwSize *dims;
//dims = mxGetDimensions(prhs[0]);
//M = (int)dims[0]; N = (int)dims[1];
A = mxGetData(prhs[0]);
mexPrintf("%d\n", A[0]);
Answers (1)
James Tursa
on 27 Jun 2016
Edited: James Tursa
on 27 Jun 2016
You almost had it correctly. But the %d format is for integer types only, not floating point. So use one of the floating point formats, e.g. %f or %e or %g.
mexPrintf("%f\n", A[0]);
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!