'"drawnow" function makes working slow.

21 ビュー (過去 30 日間)
Suk Bum Lee
Suk Bum Lee 2022 年 3 月 1 日
回答済み: Vinayak 2024 年 1 月 10 日
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 件のコメント
KSSV
KSSV 2022 年 3 月 1 日
You try with set command.
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 Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by