Find source of stopped simulation in Simulink

8 ビュー (過去 30 日間)
Stefan H
Stefan H 2022 年 10 月 12 日
コメント済み: Stefan H 2022 年 10 月 13 日
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

採用された回答

Paul
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]
  1 件のコメント
Stefan H
Stefan H 2022 年 10 月 13 日
Thank you very much Paul!
Works perfectly :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by