Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Refreshdata slowing down unrelated plots/functions

1 回表示 (過去 30 日間)
André C. D.
André C. D. 2019 年 8 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello,
I am working on a continuous while loop that involves two subplots, one of which is fairly simple and is plotted/updated continuously, and the other is fairly complex and is only plotted/updated when called by an uicontrol button press. In summary, the code looks like this:
%% ...
dialogBox1 = uicontrol(gcf,'Position',[20 20 100 30],'String','Break','Callback','delete(gcbf)');
dialogBox2 = uicontrol(gcf,'Position',[160 20 100 30],'String','Update','Callback',@update_plot);
while(ishandle(dialogBox1))
tic
[A,B,C,D,E,F] = mex_function();
%% ...
subplot(1,2,1)
plot_function1(A,B,C);
time = [time,toc];
end
%% ...
function update_plot(~,~)
subplot(1,2,2)
plot_function2(); %function uses defined global variables for plotting
end
I changed this to work with refreshdata for subplot(1,2,1), initialising the plot before the while loop, and then simply updating the variables A, B and C for the plot handles defined by plot_function1(A,B,C). While this works, everytime I use plot_function2(), the time taken between iterations becomes increasingly slower, although the two functions have nothing to do with each other.
For comparison, this is how the two methods compare (here, I am using refreshdata on the right):
Those peaks usually happen when the second subplot is updated, it's not an issue, the only problem is the increase in time afterwards (i.e. 0.1999s vs. 0.65628s), although the second plot is no longer being updated. Can anyone explain to me why that is?
Thank you in advance!

回答 (1 件)

Neuropragmatist
Neuropragmatist 2019 年 8 月 6 日
I'm not really familiar with uicontrols, but you could try clearing your axes when they are updated.
i.e.
function update_plot(~,~)
subplot(1,2,2)
cla;
plot_function2(); %function uses defined global variables for plotting
end
  1 件のコメント
André C. D.
André C. D. 2019 年 8 月 13 日
Hi, thanks for the suggestion. I've tried it, but unfortunately, the performance didn't improve.

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by