Slow simulation when Listeners are added

4 visualizzazioni (ultimi 30 giorni)
Ninad
Ninad il 16 Set 2024
Risposto: Jatin il 16 Set 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...

Risposte (1)

Jatin
Jatin il 16 Set 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!

Categorie

Scopri di più su Manual Performance Optimization in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by