Show/hide a line in uiaxes takes up to 1.5 sec
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
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
Antworten (1)
Mattias Arlbrant
am 9 Dez. 2021
1 Kommentar
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
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!