GUI slows down when plotting to figure sequentially

18 views (last 30 days)
Joe
Joe on 26 Oct 2017
Edited: Joe on 31 Oct 2017
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 Comment
Adam
Adam on 26 Oct 2017
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.

Sign in to comment.

Answers (2)

Rik
Rik on 26 Oct 2017
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 Comment
Joe
Joe on 26 Oct 2017
@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.

Sign in to comment.


Yair Altman
Yair Altman on 26 Oct 2017
Edited: Yair Altman on 26 Oct 2017
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)

Categories

Find more on Line Plots 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!