pause vs drawnow in app designer
Show older comments
Hi folks,
in my current function I used drawnow to update a figure in a while loop. But drawnow seems to slow down the programm (there are lots of topics on this). I know about the drawnow limitrate, but this command doesn't work with Matlab Compiler (figure begins to blink when compiled).
So today i tried to use the pause command instead of drawnow. This seems to speedup the code and the redrawing of the figure but all the interactivity of callbacks get's lost (needs lots of time!!!).
Is there anything else I could try to increase the performance of my code?
1 Comment
Ameer Hamza
on 13 Oct 2020
What about using pause() every n-th (say, n=5) iteration.
Answers (2)
Mario Malic
on 13 Oct 2020
I use drawnow in combination with the pause of 0.1s. I did not experiment with the values of pause.
while
%code
drawnow
pause (0.1)
end
They don't get lost, it's just that they get queued because program waits as it has been told.
12 Comments
Dominik Müller
on 13 Oct 2020
Mario Malic
on 13 Oct 2020
No need for the second pause, try increasing it to 0.01, as 0.005 is super low.
Dominik Müller
on 13 Oct 2020
Mario Malic
on 13 Oct 2020
Figure blinking might be the issue with the focus or when you use uigetfile/uigetfolder etc.
Due to the fact that you had two figures, drawnow might focus one and then the other causing the blink. I am not familiar with the details what that function actually does.
Mario Malic
on 13 Oct 2020
Dominik's comment:
no I only had one figure all the time. But if I plot on a seperate figure instead of an UIAxes the figure blinks if I use drawnow limitrate.
Now I get to another point: Is it possible that drawing on an UIAxes is less efficient than drawing on a common figure?
Updating figure in while loop might be heavy on the resources, can you show example of code you're using within while loop. This might be also useful for your plots refreshdata.
Dominik Müller
on 13 Oct 2020
Edited: Dominik Müller
on 13 Oct 2020
Dominik Müller
on 13 Oct 2020
Bruno Luong
on 13 Oct 2020
Instructive. Comparison like this comforts me that I should stay on GUI rather than switch to app Designer
Mario Malic
on 13 Oct 2020
Edited: Mario Malic
on 13 Oct 2020
What is purpose of addpoints? The way it is written is similar to plot function which will have same or maybe better performance. drawnow refreshes all figures, even having one is an issue if you would like to have it refreshed dozens of times.
for k = 1:length(x)
tic
addpoints(h,x(k),y(k));
drawnow
nToc = nToc + 1;
toc_calc = toc_calc + toc;
end
There are some examples on animatedline documentation to speed up animation, by adding more than one point at a time and so on.
You can also try by setting the XData and YData properties of UIAxes (not sure if this is possible with animatedline) within the loop by adding the elements together, that way you avoid the plot function, and only use drawnow to refresh data.
Bruno Luong
on 13 Oct 2020
Edited: Bruno Luong
on 13 Oct 2020
Under the hood of animatedline is perhaps set x, y data with better handling of FIFO graphical data points.
I try to replace with SET, it does not get any visible faster update, and the conclusion is the same, updatinf plot (happens with drawnow is 3-4 time slower on UIAxes than regular axes.
Regardless the conclusion of the test here is that drawing on uiaxes has poor performance. There is nothing end user can do about it.
Mario Malic
on 13 Oct 2020
Actually it's not the uiaxes, it's the issue with uifigure. What exactly with it, I wouldn't know.
fig = figure; % 0.124s
ax = axes(fig);
fig = figure; % 0.152s
ax = uiaxes(fig);
Bruno Luong
on 13 Oct 2020
Edited: Bruno Luong
on 13 Oct 2020
Confirmed, I cross check,
matlab.graphics.axis.Axes in UIfigure (app designer): slow 0.0303
ax = axes(figure): fast 0.0071
ax = uiaxes(figure): fast 0.0079
Dominik Müller
on 13 Oct 2020
0 votes
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!