MATLAB Answers

pause vs drawnow in app designer

54 views (last 30 days)
Dominik Müller
Dominik Müller on 13 Oct 2020
Edited: Bruno Luong on 13 Oct 2020
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
Ameer Hamza on 13 Oct 2020
What about using pause() every n-th (say, n=5) iteration.

Sign in to comment.

Answers (2)

Mario Malic
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.
pause (0.1)
They don't get lost, it's just that they get queued because program waits as it has been told.


Show 9 older comments
Bruno Luong
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
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
Bruno Luong on 13 Oct 2020
Confirmed, I cross check, in UIfigure (app designer): slow 0.0303
ax = axes(figure): fast 0.0071
ax = uiaxes(figure): fast 0.0079

Sign in to comment.

Dominik Müller
Dominik Müller on 13 Oct 2020
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?


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!