Info

This question is closed. Reopen it to edit or answer.

Refreshdata slowing down unrelated plots/functions

1 view (last 30 days)
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!

Answers (1)

Neuropragmatist
Neuropragmatist on 6 Aug 2019
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 Comment
André C. D.
André C. D. on 13 Aug 2019
Hi, thanks for the suggestion. I've tried it, but unfortunately, the performance didn't improve.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!