Find source of stopped simulation in Simulink
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello everybody,
in Simulink there are multiple ways to stop a simulation. Examples:
1.) ... "StopTime" has been reached
2.) ... input of a Stop Block is nonzero
3.) ... set_param( gcs, 'SimulationCommand', 'stop' )
Now I was wondering if there's a way to find out what exactly caused my simulation to stop.
In my case especially the third case has to be treated differently.
Using
get_param( gcs, 'SimulationStatus' )
does not work, because the answer in all three cases is 'stopped'.
Any help would be very much appreciated.
Best regards,
Stefan
댓글 수: 0
채택된 답변
Paul
2022년 10월 12일
편집: Paul
2022년 10월 13일
Hi Stefan,
If you use the sim command, then the output has some useful information. For example, I used a model with a Clock, feeding Compare To Constant (>= 3), feeding a Stop Simulation.
In this case, I set the Tfinal = 2.
>> y = sim('untitled');
>> y.SimulationMetadata.ExecutionInfo
ans =
struct with fields:
StopEvent: 'ReachedStopTime'
StopEventSource: []
StopEventDescription: 'Reached stop time of 2'
ErrorDiagnostic: []
WarningDiagnostics: [0×1 struct]
After a change to the model to set Tfinal = 10.
>> y = sim('untitled');
>> y.SimulationMetadata.ExecutionInfo
ans =
struct with fields:
StopEvent: 'ModelStop'
StopEventSource: [1×1 Simulink.SimulationData.BlockPath]
StopEventDescription: 'Stop requested by untitled/Stop Simulation'
ErrorDiagnostic: []
WarningDiagnostics: [0×1 struct]
I don't normally use set_param to control excution status of the model, so couldn't come up with an example of that to test.
If using the Play button, then make sure that Model Settings -> Data Import/Export -> Single simulation ouput is checked (which is the default). The default name for the output variable is 'out' (you can change this). Then, after clicking Play
>> out.SimulationMetadata.ExecutionInfo
ans =
struct with fields:
StopEvent: 'ModelStop'
StopEventSource: [1×1 Simulink.SimulationData.BlockPath]
StopEventDescription: 'Stop requested by untitled/Stop Simulation'
ErrorDiagnostic: []
WarningDiagnostics: [0×1 struct]
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!