Find source of stopped simulation in Simulink
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stefan H
el 12 de Oct. de 2022
Comentada: Stefan H
el 13 de Oct. de 2022
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 comentarios
Respuesta aceptada
Paul
el 12 de Oct. de 2022
Editada: Paul
el 13 de Oct. de 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]
Más respuestas (0)
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!