Hi, I have declared a pointer to a float
float *myvariable;
I initialize this to
myvariable = mxCreateNumericMatrix(256,1,SINGLE (sorry for not the exact syntax),0);
Then I call a function func(myvariable);
This function does math on myvariable and returns the pointer.
Now if I have to output this variable, I get Matlab crash with this:
mxSetData(plhs[0],(float*)myvariable);
I have tried mxFree before the line but still a problem.
Questions: 1. If the second parameter is void according to definition how come my program compiles fine without error.
2. Why does Matlab crash (implying memory leak)?
3. The other option works and this is
plhs[0] = mxCreateNumericArray(256 matrix of SINGLE 0) and finally myvariable=mxGetData(plhs[0]); func(myvariable);
The reason I do not like this way is
a. I would prefer to run the function first and then assign the return to plhs[0];
b. It is a very ugly way of doing it like this, though it works.
c. I would at some point like to declare "myvariable" to be static so that every time it is requested by Matlab function some.m, I do not initialize it to 0. And I have many such variables to work with. I am updating data every fraction of a second for several minutes.
And I have to work with floats
Thanks