Show/hide a line in uiaxes takes up to 1.5 sec

1 Ansicht (letzte 30 Tage)
Mattias Arlbrant
Mattias Arlbrant am 25 Nov. 2021
Background: I have a large application designed in AppDesigner. It contains an UIAxes. In the UIAxes I have ~40 lines (512 points each, created with semilogx). Typically I only want to plot 1-8 of these simultaneously. Checkboxes control which of the lines should be visible. The plot x,y data is pre-computed.
Problem: I want to be able to show/hide the plots without waiting seconds for anything to happen; the problem is that it takes a ridiculously long time before a click on a checkbox reflects in a plot update. Up to 1.5 seconds!
What I have tried: I have tried two methods to manage the lines:
A) Plot everything; save the handles, use set(...,'Visible',val) from the checkbox callbacks to hide/show individual lines
B) Plot-on-demand; a plot is created (data is pre-computed so no delay there) and tagged when a checkbox changes state to true, and calling delete(findobj('Tag',tag)) when a checkbox changes state to false
The performance is equally bad for both A and B. I do not understand why changing visibility is such an incredibly slow operation. Are there any other ways to do this? Have I missed any important settings? Is the complexity of my mlapp (several tabs with components) somehow a problem?
Help would be much appreciated!
  3 Kommentare
Mattias Arlbrant
Mattias Arlbrant am 6 Dez. 2021
Hi Michael, Thank you very much for your reply!
  • I have a single main uiaxes and below it10 tabs. Cannot reduce the number.
  • I also found legends completely unusable so I am not using any (even though people keep asking me to add them).
  • I have played around with various variations of drawnow but it made no difference. I guess I could probably experiment with moving it to some ideal place in the code, although I am not sure where that would be because I basically have a callback, a function call, access to pre-calculated member variables of the mlapp followed by set(...,YData
  • I am not sure what you mean by "passing the UIAxes as appropriate", maybe I have missed something? Or maybe this is irrelevant since I have only one axes? What I do is set(plotHandle,'YData',val) where plotHandle = semilogx(axesHandle,X,Y)
  • The profiler is not helpful because the sluggishness seems to be all in matlab's internal code.
I think the problem is in mathworks's plot handling. It seems as if it re-renders everything, including everything that is set to "invisible", after even a small change to any of the plotted lines. But even that would not explain the truly extreme delay in the plot updates.
By the way, my pc cannot be blamed, every other application runs just fine with great performace. Only matlab has problems, and only the mlapp.
Michael Van de Graaff
Michael Van de Graaff am 9 Dez. 2021
you've probably already found these but if not maybe there's somehting there:
what if you just start over every time? for example, I would try something like this to start (where the data are packaged in the 1x40 struct array data)
nlines = 40;
ax = app.UIaxes;
cla(ax);
hold on
for ii = 1:nlines
if data(ii).plot_flag
xdata = log(data(ii).x(:)); % just to rule out semilogx being the issue
ydata = data(ii).y(:);
plot(ax,xdata,ydata); % obviously your data might be packaged differently
end
end

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mattias Arlbrant
Mattias Arlbrant am 9 Dez. 2021
Well I tried method "B" (deleteing and re-plotting one line) above, and it was equally slow as "A". I don't think clearing and re-plotting every single line will speed things up.
  1 Kommentar
Michael Van de Graaff
Michael Van de Graaff am 9 Dez. 2021
I'm not saying clear and replot the line, i'm saying clear and replot the whole figure, and only plotting the lines you need.
maybe that sounds absurd, but intuition is a tricky thing. for example, elementwise exponentian in matlab is sometimes faster in a loop
mat = rand(1000);
tic
mat2 = mat.^10;
toc
mat3 = ones(1000);
tic
for ii = 1:10
mat3 = mat3.*mat;
end
toc
sum(sum(mat2-mat3)) %to show mat2 and mat3 are equal
which is not at all what I would have expected

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by