'"drawnow" function makes working slow.

21 Ansichten (letzte 30 Tage)
Suk Bum Lee
Suk Bum Lee am 1 Mär. 2022
Beantwortet: Vinayak am 10 Jan. 2024
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 Kommentare
KSSV
KSSV am 1 Mär. 2022
You try with set command.
Suk Bum Lee
Suk Bum Lee am 1 Mär. 2022
How can I use 'set' command in above codes?
Could you elaborate in detail?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Vinayak
Vinayak am 10 Jan. 2024
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.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by