To Workplace delays data write out when simulation is paused
3 views (last 30 days)
Show older comments
Dear folk,
I have a simulation which is paused at a certain time (using Assertion block) and continued (using set_param) from my Matlab function afterwards. When the simulation is paused, I need to process data written out by "To Workplace" blocks before I continue the simulation.
The issue I'm facing is that the data is not provided to my workplace (i.e. my function) immediately after the pause, therefore the very first line that runs after the pause returns an error complaining that there is not such data. I was able to fix this by including a pause(1) right after the simulation is paused, so that in the 1s buffer time I'm providing, the data arrives into my workplace.
However, I cannot afford the 1s pause since I'm running thousands of simulation and that adds up quickly. Also, strangely enough, when I do the same trick in a While loop, even with greater pauses (3s or more), the data still doesn't get to my variables in time and leaves me with an error.
So I guess my questions come down to: (1) is there a way to force the "To Workplace" block to write out data immediately after the simulation paused? (2) Or do you know of an alternative way to do what I'm trying to do?
Wondering if anyone knows something about this and can provide some hint. Thanks.
2 Comments
Pawel Ladosz
on 2 Sep 2016
Edited: Pawel Ladosz
on 2 Sep 2016
How big is the data from 'to workspace'?
Answers (1)
Fangjun Jiang
on 2 Sep 2016
Edited: Fangjun Jiang
on 2 Sep 2016
try set_param('Model','SimulationCommand','WriteDataLogs') or set_param('Model','SimulationCommand','Update') to force it.
It may have no effect according to the document,
"When you use set_param to start, pause, continue or stop a simulation, these commands are requests for such actions and do not get executed immediately. ..."
web(fullfile(docroot, 'simulink/ug/using-the-set-param-command.html#responsive_offcanvas'))
2 Comments
Fangjun Jiang
on 2 Sep 2016
It has to be in the callback of the Assertion block if you want to make the whole process automatic. It shouldn't matter where it is called. Maybe it is due to the fact that it takes a little bit time to write the two 1*5000 matrix. Please pay attention to the note that I added. You could also try set_param('Model','SimulationCommand','update'). In the document, it was meant to "Update Workspace Variables Dynamically During Simulation". It might take more or less time than puase(1) depending on your model.
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!