Simulink Run and Command Window sim(); differences
7 views (last 30 days)
Show older comments
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 Comments
Chao Luo
on 15 Feb 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.
Answers (1)
Raghav
on 7 Apr 2023
Edited: Raghav
on 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 Comments
Chris
on 21 Sep 2023
Can you explain how to check the settings of the Simulink simulation engine vs the MATLAB simulation engine?
Paul
on 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?
See Also
Categories
Find more on Get Started with GPU Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!