Kate J.
Posts:
160
Registered:
6/9/11
|
|
Re: How to record individual timestep data in Simulink?
Posted:
Sep 4, 2012 3:06 PM
|
|
Thanks for your suggestion, Phil. It makes sense to me. However, when I had the chance to try it out, I found that while the syntax ?mxSetPr(array_ptr, &varMEX);? allows the code to compile, it actually causes a crash when the system runs. (If I comment out this line, the code runs with no problems.) If my code is given below, any suggestions about what else could be the issue, such that running this code results in crash behavior? Thanks.
mxArray *array_ptr; double varMEX;
array_ptr = mxCreateDoubleMatrix(1,1,mxREAL); array_ptr = mexGetVariable("base","Timestep"); varMEX = mxGetPr(array_ptr)[0];
---------------
if(varMEX < value){ ? }
/* all code above this point works */ ----------------
/* problematic part: returning the value to the base workspace */
varMEX = 100.0; /* reset varMEX to arbitrary value */ mxSetPr(array_ptr, &varMEX); /* causes a crash */ mexPutVariable("base","Timestep",array_ptr); mxDestroyArray(array_ptr);
|
|