GUI slows down when plotting to figure sequentially
18 views (last 30 days)
Show older comments
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
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.
Answers (2)
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.
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:
0 Comments
See Also
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!