pause vs drawnow in app designer
이전 댓글 표시
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
Ameer Hamza
2020년 10월 13일
What about using pause() every n-th (say, n=5) iteration.
답변 (2개)
Mario Malic
2020년 10월 13일
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
Dominik Müller
2020년 10월 13일
Mario Malic
2020년 10월 13일
No need for the second pause, try increasing it to 0.01, as 0.005 is super low.
Dominik Müller
2020년 10월 13일
Mario Malic
2020년 10월 13일
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
2020년 10월 13일
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
2020년 10월 13일
편집: Dominik Müller
2020년 10월 13일
Dominik Müller
2020년 10월 13일
Bruno Luong
2020년 10월 13일
Instructive. Comparison like this comforts me that I should stay on GUI rather than switch to app Designer
Mario Malic
2020년 10월 13일
편집: Mario Malic
2020년 10월 13일
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
2020년 10월 13일
편집: Bruno Luong
2020년 10월 13일
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
2020년 10월 13일
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
2020년 10월 13일
편집: Bruno Luong
2020년 10월 13일
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
카테고리
도움말 센터 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!