'"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
回答 (1 件)
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 “set” command (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 use “drawnow” or “drawnow limitrate” as needed after updating the plot to ensure the display is refreshed.
I hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!