Is there a way to abort Simulink simulation programatically if it takes a long time?

조회 수: 18 (최근 30일)
I have a model that, depending on some variable values sometimes runs very slowly. Typically I try out many different variable values in a loop, i.e. I start the simulation from a MATLAB script. Is there a way to abort the simulation without breaking the loop if the simulation takes too long?

채택된 답변

Rob Graessle
Rob Graessle 2011년 1월 25일
Walter is correct about using a timer object that is configured to fire at the end of the wait period. In the timer callback you can use the following command to stop the simulation:
set_param('ModelName', 'SimulationCommand', 'stop')
where ModelName is the name of the model you are simulating.
For more information, check out Running a Simulation Programmatically.

추가 답변 (2개)

R
R 2011년 1월 26일
The way I solved was basically like this.
myTimer = timer('StartDelay',10, 'TimerFcn','set_param(''ModelName'',''SimulationCommand'',''stop'')');
for KpGain = 1:10
start(myTimer);
sim('ModelName');
stop(myTimer);
end
delete(myTimer);
I guess that in a parfor loop you would have to be a little more careful of having different timers for different workers, right?

Walter Roberson
Walter Roberson 2011년 1월 25일
In the MATLAB routine you could start a timer that would fire at the end of your wait. In the timer callback, you would instruct the simulation to stop.
I do not know the details at all, as I have not used simulink. It might involve setting a parameter and using a STOP block; see a recent cssm post
There appears to be some other useful information in this cssm post

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by