Find source of stopped simulation in Simulink

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Paul
Paul il 12 Ott 2022
Modificato: Paul il 13 Ott 2022
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]

Più risposte (0)

Categorie

Scopri di più su Programmatic Model Editing in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by