Effacer les filtres
Effacer les filtres

Simulink Run and Command Window sim(); differences

9 vues (au cours des 30 derniers jours)
Matteo Bordignon
Matteo Bordignon le 12 Fév 2023
Commenté : Paul le 22 Sep 2023
I developed a model of my system in Simulink; it should run and display an animation, depicting the evolution of the system.
I am noticing differences in the behivour of the simulation when pressing on the "Run" button in Simulink and using the sim("mymodel.slx") in Matlab; the main difference is the usage of the dedicated GPU (active while the command is run in Matlab, not active when the simulation is started directly on Simulink), resulting in a very laggy animation. Moreover, there where also problems in displaying the figure of the animation when running with the Run button in Simulink.
To solve this problem I tried to use the GPU Coder package with, unfortunately, very poor results: the time to compile the model grew a lot (few seconds to minutes) and using the Windows Task Manager i could still see the dedicated GPU still off, resulting again in a poor quality of the animation. I don't think this package is needed since everything was running smoothly without it when the simulation was run from the Matlab Command Line.
Why is this happening? Shouldn't in theory the 2 option provide the same result? Does someone have a solution for this? Running every time from Matlab is limiting (for example i cannot Pause the execution, but only Stop it with Ctrl+C) and annoying.
  2 commentaires
Chao Luo
Chao Luo le 15 Fév 2023
With GPU Coder it would compile the model in a way that tries to parallelize simulation. But it may not be able to parallelize depending on how the model is implemented. It takes longer time to compile is expected. Based on your obeservation, it seems no computation is parallelized on GPU.
It looks to me the problem is running MATLAB, it uses GPU to show the animation, but not when it is running from Simulink. Currently, GPU Coder would not change the way how animination is displayed.
Matteo Bordignon
Matteo Bordignon le 16 Fév 2023
Thank you for the GPU Coder clarification.
The problem is exacly the one you mentioned. Is there a way to make Simulink use the GPU for the animation? I tried looking in Windows Graphics Settings in order to change Simulink to 'High Performance' since it helped with MATLAB scripts but i cannot find the app. I guess it's because Simulink is not a separeted app with respect to matlab.

Connectez-vous pour commenter.

Réponses (1)

Raghav
Raghav le 7 Avr 2023
Modifié(e) : Raghav le 22 Sep 2023
Hi,
Based on your question, I understand that you are facing difference in model simulation while executing through Simulink and command window.
There could be several reasons why you are observing differences in the behavior of your Simulink model when running it using the "Run" button in Simulink versus the "sim" command in MATLAB. One possible reason could be related to the configuration of your Simulink model or the settings of your MATLAB environment.
When you run the simulation using the "Run" button in Simulink, Simulink uses its own simulation engine to run the simulation, which may have different settings and configurations than the MATLAB environment you are using to run the "sim" command. This can result in different performance and behavior of the simulation.
On the other hand, when you run the simulation using the "sim" command in MATLAB, you are directly invoking the MATLAB simulation engine, which may have different settings and configurations compared to the Simulink simulation engine.
Regarding the usage of the dedicated GPU, it is possible that the Simulink simulation engine is not configured to use the GPU, while the MATLAB simulation engine is. This can lead to the observed differences in performance and behavior.
To resolve this issue, you may want to check the settings and configuration of your Simulink model and the MATLAB environment to ensure that they are consistent. You can also try to configure the Simulink simulation engine to use the GPU if possible.
Overall, it is difficult to provide a specific solution without more information about your Simulink model and the MATLAB environment you are using.
Thanks,
Raghav Bansal
  2 commentaires
Chris
Chris le 21 Sep 2023
Can you explain how to check the settings of the Simulink simulation engine vs the MATLAB simulation engine?
Paul
Paul le 22 Sep 2023
More generally, what is the distinction between the "Simulink simulation engine" and the "MATLAB simulation engine." Is there a doc page the explains this?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulation dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by