Use of a user defined pointer to mxArray.
Show older comments
This has always bugged me about working with MEX-functions. Here is how I always end up working with the return argument from a MEX- function.
plhs[0] = mxCreateNumericArray(I,J,mxDOUBLE_CLASS,mxREAL);
for (ii=0;ii<M;ii++)
mxGetPr(plhs[0])[ii] = mxGetPr(prhs[0])[ii];
This works fine, but what I would like to do is find a way to not have to call mxGetPr every time through each and every loop in the file. To this end I tried this (starting with lhs):
mxArray *Ar; // initialize at beginning of file.
plhs[0] = mxCreateNumericArray(I,J,mxDOUBLE_CLASS,mxREAL); // SWITCH
Ar = mxGetPr(plhs[0]);// What is the point of this if I can't use it?
for (ii=0;ii<M;ii++)
*(Ar+ii) = mxGetPr(prhs[0])[ii];
But I get compile errors referencing: 'mxArray *' : unknown size.
The problem is that the return type is not known at compile time, so is there no way around using mxGetPr in such a case? I have had similar errors when working only with the prhs.
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Compiler 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!