Yi
Posts:
6
Registered:
12/28/12
|
|
Re: mexCallMATLAB crashes in loops?
Posted:
Jan 2, 2013 5:36 PM
|
|
Thank you, James. Actually I only need one of the structure element each time for the function input, and I was messing up when setting the field values for the incall.
I fixed the code in this way:
: for(istruct=0;istruct<ninputs;istruct++){ for(ifield=0; ifield<nfields; ifield++){ tmp=mxDuplicateArray(mxGetFieldByNumber(prhs[0],istruct,ifield)); mxSetFieldByNumber(incall[0], 0, ifield, tmp); } : mxDestroyArray(mout[0]); }
I got some ideas from this thread: http://www.mathworks.co.kr/matlabcentral/newsreader/view_thread/280511
So I cleaned the mout[0] in each loop and cleaned the incall[0] in the end. The code works for now yet I still have a question:
Is it necessary to clean the mout[0] in the loop? Can I clean it up in the end of the code (with incall[0])?
Thank you again for your helpful replies :)
|
|