Slow simulation when Listeners are added
4 次查看(过去 30 天)
显示 更早的评论
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...
0 个评论
回答(1 个)
Jatin
2024-9-16
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manual Performance Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!