Show/hide a line in uiaxes takes up to 1.5 sec
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Michael Van de Graaff
2021년 12월 9일
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
답변 (1개)
Mattias Arlbrant
2021년 12월 9일
댓글 수: 1
Michael Van de Graaff
2021년 12월 9일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!