'"drawnow" function makes working slow.

21 次查看(过去 30 天)
I'm using timer in app designer.
Between timer operation, I'm using drawnow for instant plotting.
Up to 2020b version, it has been working fine.
But, in 2021a, I have the issue of hagning or very slow update issue.
When I remove the drawnow, it looks working fine.
Is there any better method without revmoving "drawnow"?
Also, can you explain why it is only happened in 2021a?
I already tried "drawnow limitrate". But, it is same.
% timer
app.updateTimer=timer('BusyMode', 'drop', 'ExecutionMode','fixedSpacing','Period', 0.01,'TimerFcn',@(~,~)app.updateTimerISR);
% it is called during timer
function plot_refresh(app)
g=app.graph_main;
cla(g);
switch app.disp
case 1
switch app.x_axis_unit
case 1
plot(g,app.data.x_bin,app.data.y);
case 2
plot(g,app.data.x_cf,app.data.y);
end
case 0
switch app.x_axis_unit
case 1
x=app.data.x_bin;
case 2
x=app.data.x_cf;
end
y=((-app.es_wbch_hw.num_cap+1):0)';
s=pcolor(g,x,y,app.data.y_cap);
s.EdgeColor='none';
end
drawnow();
end
  2 个评论
Suk Bum Lee
Suk Bum Lee 2022-3-1
How can I use 'set' command in above codes?
Could you elaborate in detail?

请先登录,再进行评论。

回答(1 个)

Vinayak
Vinayak 2024-1-10
Hi Suk,
I understand you were facing performance issues with “drawnow”. If you are still facing similar issues in latest MATLAB releases, you might want to consider updating the data of your plot rather than redrawing them entirely. This can be done by using the setcommand (as suggested by KSSV) to modify the properties of your existing plot objects. Here's how you can optimize your plot_refresh function:
First, when you create your initial plot, store a handle to it:
app.plotHandle = plot(g, app.data.x_bin, app.data.y);
Then, during your timer callback, you can update the plot data using the stored handle:
set(app.plotHandle, 'XData', app.data.x_bin, 'YData', app.data.y);
This approach updates the plot without the overhead of redrawing everything, which should improve the responsiveness of your application. Remember to usedrawnowor drawnow limitrateas needed after updating the plot to ensure the display is refreshed.
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by