Slow simulation when Listeners are added

3 Ansichten (letzte 30 Tage)
Ninad
Ninad am 16 Sep. 2024
Beantwortet: Jatin am 16 Sep. 2024
I am creating a GUI for an application where in I have to read input data from ports in a subsystem(as input blocks are virtual blocks) where signal values pass through and also from output ports and plot the datapoints against simulation time datapoints in real time . And for that I have created listeners to read the signal values. But now when I run my simulation through my GUI the simulation of the simulink model runs very slow(which is not the case when the simulation is run without GUI). Anyone out there, who can suggest any method to make the process efficient? Or is it the thumb rule that if I use listeners the simulation is bound to be slow and there is no workaround. Would really appreciate if someone could help me...

Antworten (1)

Jatin
Jatin am 16 Sep. 2024
Hi @Ninad,
Running a Simulink model with real-time data acquisition and plotting through a GUI, updated using listeners, can indeed slow down the simulation. This slowdown is due to factors such as continuously monitoring signals, updating plots with each change, and rendering the GUI. Below are some points which can help you improve performance.
1. Instead of redrawing the entire plot, try updating only the values that have changed. You can use the "set" function to achieve this efficiently. Additionally, preallocating memory for large data sets can improve performance.
2. You can decrease the frequency of listener updates by, for instance, refreshing the plot after a few simulation steps or seconds.
3. If not already in use, consider employing fixed-step solvers, as they can be more efficient for real-time applications.
4. You can also utilize the MATLAB Profiler to identify bottlenecks in your code and optimize those sections for better performance.
Kindly refer to the documentations below for more details on "set" and "profiler":
Hope it helps!

Kategorien

Mehr zu Manual Performance Optimization finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by