Why can't I continue my simulation using 'PauseFcn' callback?

조회 수: 15 (최근 30일)
I am pausing my simulation using an assertion block, as shown in below documentation example:
Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation
>> web(fullfile(docroot, 'simulink/ug/controlling-execution-of-a-simulation.html'))
I tried to add below simulation command to the 'PauseFcn' callback to resume the simulation automatically, but it doesn't work:
set_param(bdroot,'SimulationCommand','continue')
However, I can continue the simulation if I enter the command manually at the MATLAB Command Prompt. Why is this?
Please follow the below link to search for the required information regarding the current release:

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 7월 29일
편집: MathWorks Support Team 2024년 8월 29일
Since MATLAB Release 2016a, it is not possible the continue a simulation using 'PauseFcn' callback anymore.
We disallowed calling "set_param(gcs,'SimulationCommand','continue')" from the 'PauseFcn' callback, as this is the kind of thing that can easily end up in an infinite recursion if not done properly.
There is currently no workaround to achieve the old behavior; so the best way to move things forward would be to look into other alternate workflows that would be more robust to achieve what you really need.
For example, if you perform co-simulation, an S-Function could do something similar to what the 'PauseFcn' callback is doing. You would not need to pause, the S-Function would call the external environment, wait for it to do its thing and when it is done, it would keep moving forward. That would be a lot more robust and would probably be faster too.
If it is absolutely necessary to retain this workflow, please consider the following workaround in the "PauseFcn" callback:
xx = timer('ExecutionMode','singleShot','StartDelay',0.1,'TimerFcn','set_param(bdroot, ''SimulationCommand'', ''continue'')');
start(xx)
In summary, one creates a timer object and attaches the "continue" function, and then start the timer which will then continue the simulation after the "PauseFcn" callback is exited.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by