Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How to record individual timestep data in Simulink?
Replies: 10   Last Post: Sep 5, 2012 2:04 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kate J.

Posts: 177
Registered: 6/9/11
Re: How to record individual timestep data in Simulink?
Posted: Sep 4, 2012 3:06 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.