Get Simulation Phase of Simulink Model

I want to get the current simulation phase of my Simulink model.
Let's take the 'busdemo' model as an example.
open_system('busdemo')
busdemo([],[],[],'compile');
Now the model is in the 'compile' phase and I want to get this information in Matlab.
The Simulink Report Generator seems to provide a check if the model is in the compile phase:
However I'm restricted to Matlab 2016b and I think there should be another way to get the current simulation phase.
Cheers,
Patrick

 Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 20 Mai 2021

1 vote

Check the status of a simulation.
get_param('ModelName','SimulationStatus')
The software returns 'stopped', 'initializing', 'running', 'paused', 'compiled', 'updating', 'terminating', or 'external' (used with the Simulink Coder™ product).

4 commentaires

Patrick Merz
Patrick Merz le 20 Mai 2021
Modifié(e) : Patrick Merz le 20 Mai 2021
Thanks for your comment.
This solution is sufficient for the problem I want to solve.
However if I run the command for my example, Matlab returns 'paused' as the SimulationStatus.
I tested this in Matlab R2016b and R2020b
pen_system('busdemo')
busdemo([],[],[],'compile');
get_param('busdemo','SimulationStatus')
Fangjun Jiang
Fangjun Jiang le 20 Mai 2021
Maybe wait a little till the compiling is completed and then get the SimulationStatus?
The corresponding command to change the status is to set the 'SimulationCommand'. set_param('ModelName','SimulationCommand','continue'), 'start', 'pause', 'stop', etc.
Patrick Merz
Patrick Merz le 20 Mai 2021
Nope, waiting does not help. Simulink also states that the model is in the 'compiled' state.
I force the model to stay in the 'compiled' state, so I cannot set the parameter to 'continue'.
It seems to be a minor bug, that the SimulationStatus outputs'paused' in this case.
But thanks for your comment, as I mentioned it is sufficient for my problem to see that the state is 'paused'.
Fangjun Jiang
Fangjun Jiang le 20 Mai 2021
It is probably not a bug, but a bad name.
When you get the SimulationStatus immediately after setting the model to 'compile', it returns 'paused' (though the name 'paused' does not make sense). If the compiling is finished, it returns the status as 'compiled', which makes sense.
'continue' is used to change status after setting 'SimulationCommand' to 'pause'.
To change your status, I think it is model([],[],[],'term')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by