GUI slows down when plotting to figure sequentially

14 次查看(过去 30 天)
I built a MATLAB GUI that displays images in 9 figures. It also displays one graphical x vs y plot in another figure in the GUI. The images and data for the plot are read all at once but displayed sequentially. We have thousands of images to display. When the GUI runs showing the images (using the imagesc command) only (commenting out the plotting x vs y section), it runs at an acceptable, steady speed. But when I run the GUI updating and plotting (using the plot command) the x vs y plot figure, it starts at an OK speed but quickly slows down to a crawl. For the x vs y plot, I’m using a code similar to the one provided as an answer here: https://www.mathworks.com/matlabcentral/answers/217077-matlab-gui-updating-plot. I'm using the hold 'on' command because I want to see the history of the plot.
Is there a way to speed up this plotting to GUI?
UPDATE (Oct 31, 2017): I noticed that when I replaced the "hold(handles.window,'on')" and "hold(handles.window,'off')" by generic "hold on" and "hold off," it eliminated the gradual slow down of the display. Now it displays the images at a constant rate (with no slow down).
  1 个评论
Adam
Adam 2017-10-26
What are you actually plotting in your x vs y plot? You should be plotting it all as a single graphics object that you update. If you are plotting a new graphics object for every point then it will slow down a lot because graphics objects are expensive and even if they don't look any more on screen 100 graphics objects instead of 1 giving the same data take a lot more memory and slow your execution down a lot. 1000 even more so, etc, etc.

请先登录,再进行评论。

回答(2 个)

Rik
Rik 2017-10-26
With hold on your plot is containing more data every loop, which slows down your function. A solution is to not use hold on, but (using handles) only keeping the last few plots in your figure.
  1 个评论
Joe
Joe 2017-10-26
@Rik. Thanks for the suggestions. I did some modifications. The plot actually plots 8 curves. I was plotting one curve, holding on, then plotting the other curves. I got rid of that. I'm now making one call to plot to plot all 8 curves. I'm also plotting only 100 data points at a time and moving the xlim to keep the new data point centered. All this sped up the display but it still slows down eventually. It also executes slower than when that particular plot is turned off and I'm only displaying the images in the other GUI figures.

请先登录,再进行评论。


Yair Altman
Yair Altman 2017-10-26
编辑:Yair Altman 2017-10-26
You might find the tips mentioned in the following articles useful - many of them deal directly with graphics performance:
You might also find my book useful - "Accelerating MATLAB Performance" (CRC Press, 2014)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by