Info

此问题已关闭。 请重新打开它进行编辑或回答。

Refreshdata slowing down unrelated plots/functions

1 次查看(过去 30 天)
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