I have a mex file (compiled in VS2010, Matlab 2010b) that accepts a variable and changes it. For example, in the mex file, it looks like this:
double *fp = (double *)mxGetPr (prhs[0]); *fp = someDoubleValue;
To compare the Matlab implementation and the mex implementation, I make a copy of the variable before calling the mex file:
var_mex = var; mymex (var_mex);
To my surprise, both var_mex and var change (to the same value), as if I created a link to var , not a copy of it.
Is this a known issue? How can I convince Matlab to copy a variable?
EDIT
Since I suspected that this problem was the result of Matlab optimizing memory management, I did some βdo nothingβ calculations on var before calling the mex file, i.e.
var=var+1; var=var-1;
and indeed, he solves the problem. Anyway, I would be glad to receive some information (or other suggestions) about this if someone also came across it.
source share