App Slow With UIAxes

130 ビュー (過去 30 日間)
Ephraim Bryski
Ephraim Bryski 2020 年 8 月 4 日
コメント済み: Adam Danz 2023 年 12 月 19 日
Hi. I'm creating apps on app designer which use components such as sliders to control a plot. When plotting on a UIAxes, there is significant delay. However, when having the app plot on a separate figure, there is no delay. Does anyone know the reason for this and if there's a way to plot on the UIAxes without the delay? Thanks.
I'm going to use an app modelling a cylinder removing a lot of the additional unnecessary stuff, so the type of problem is as clear as possible. The plot consists of surf, patch, and plot3. For all apps, the goal is not plotting data per say, but rather creating shapes, often in 3 dimensions. Therefore, the data is generally arrays of type double which don't generally get over 100 elements.
I'm using MATLAB R2020a.
These are the two methods:
  • I drag and drop a UIAxes on to the app and plot on that axis. This takes about 3 seconds to update the plot each time I move the slider. This is a screenshot of the setup:
  • I create a separate regular figure (not uifigure) and plot it on that. This has almost no delay:
This is the code used to create the separate figure and have them aligned neatly (I don't think it's that important but it clarifies what I'm doing):
global ax %needed so it can be accessed through component callbacks
divide=.2;%the fraction of the screen filled by the app
set(0,'units','pixels')
pixels=get(0,'screensize');
app.UIFigure.Position=[0,0,divide*pixels(3),pixels(4)];
fig=figure; %new figure
fig.Position=[divide*pixels(3),0,(1-divide)*pixels(3),pixels(4)];
ax=axes(fig); %axis it will be plotted on
Here is the code which I used (I removed much of the code used in the original app to simplify things) (the code is based off of Clay M. Thompson's cylinder function, and I kept the copyright text in the code):
function torsion(ax,ax2,M,G,L,r,display_in)
% Clay M. Thompson 4-24-91, CBM 8-21-92.
% Copyright 1984-2002 The MathWorks, Inc.
cla(ax)
% engineering equations:
J=1/4*r^4;
phi=M*L/(J*G);
% set up cylinder:
n = 50;
r = [r r]';
r = r(:); % Make sure r is a vector.
m = length(r); if m==1, r = [r;r]; m = 2; end
theta = (0:n)/n*2*pi;
sintheta = sin(theta); sintheta(n+1) = 0;
x = r * cos(theta);
y = r * sintheta;
z = (0:m-1)'/(m-1) *L* ones(1,n+1);
hold(ax,'on')
% plot cylinder
surf(ax,x,y,z,'EdgeColor','none','FaceAlpha',1)
patch(ax,x(1,:),y(1,:),z(1,:),[.25 0 .7])
patch(ax,x(1,:),y(1,:),z(2,:),[.25 0 .7])
%plot helices
z_vals=linspace(0,L,n*L/(2*pi*r(1)));
for i=0:n-1
angle0=i*(2*pi)/n;
anglef=angle0+phi;
theta_part=linspace(angle0,anglef,length(z_vals));
x_part=(r*1.01)*cos(theta_part);
y_part=(r*1.01)*sin(theta_part);
z_vals=linspace(0,L,length(x_part));
plot3(ax,x_part,y_part,z_vals,'k','LineWidth',.5)
end
% plot circles
for i=z_vals
plot3(ax,x,y,i*ones(1,n+1),'k','LineWidth',.5)
end
end
  14 件のコメント
Adam Danz
Adam Danz 2021 年 3 月 25 日
編集済み: Adam Danz 2021 年 3 月 25 日
Good thinking to time them that way, J. Alex Lee.
Actually, the creation of figures and axes can be completely separated if the tic/toc only surrounds either the figure creation of the axes creation with a drawnow preceeding the creation.
J. Alex Lee
J. Alex Lee 2021 年 3 月 25 日
thanks @Adam Danz, I think I actually confused everyone with my above posted...the way I separated was to create the figures once and for all, and then keep deleting and creating axes inside them - so the plot I showed only reflects axes creation time, and the conclusion from that should not be "ime is really spent by the uifigure call", but rather that creating uiaxes and axes alike within an existing uifigure is slower than creating them within an existing regular figure.
And the second time test I did shows that actually, plotting might be faster within uiaxes than in regular axes once they are created, whether it be within a uifigure or a regular figure. but either way, plotting is still much faster on uiaxes or axes created in a normal figure.

サインインしてコメントする。

採用された回答

Chris Portal
Chris Portal 2020 年 8 月 7 日
Thank you @Adam Danz and @Ephraim Bryski. The additional info is useful. I see the same uifigure/uiaxes slowness Adam is showing.
Ephraim, try using a uifigure/axes combination instead. This shows similar performance results to the figure/axes combination:
  • UIFIGURE/UIAXES: Elapsed time is 1.871439 seconds.
  • UIFIGURE/AXES: Elapsed time is 0.205658 seconds.
  • FIGURE/AXES: Elapsed time is 0.204895 seconds.
A few notes:
  • UIAXES is a heavier weight version of AXES (it's effectively an axes with an invisible UI panel). This makes it slower, although the amount of slowness here is a little surprising. I'll report this to the development team to investigate.
  • The axes you get in App Designer when you drag and drop from the palette is always a UIAXES. So in order to use an AXES with your UIFIGURE, you'll need to manually create and position it as part of your startup function.
  • Lastly, these UIAXES/AXES differences will soon become a much simpler story with some up and coming work. Keep an eye out for the MATLAB release notes!
  19 件のコメント
Ford Creighton
Ford Creighton 2023 年 12 月 19 日
Thanks for the reply @Adam Danz. From what I gather, removing the tabs in the app and placing all 4 axes on a single container/app-page will speed up the linked axes panning in 2023b?
If so, I will work on migrating to 2023b in the next month or so and set a reminder to follow up here with results.
Adam Danz
Adam Danz 2023 年 12 月 19 日
> removing the tabs in the app and placing all 4 axes on a single container/app-page will speed up the linked axes panning in 2023b?
Yes, I did just that and tested it in R2023b to confirm considerable improvements in performance during panning.

サインインしてコメントする。

その他の回答 (3 件)

Matlab User
Matlab User 2021 年 3 月 21 日
編集済み: Matlab User 2021 年 3 月 21 日
I just installed Matlab R2021a and this is still not resolved - the jaw dropping UIAxis lag is still there. Maybe it was a mistake to fork Guide into a new thing...
@Chris Portal It seems no-one can reproduce your solution. Are you sure that you did not simply time FIGURE/AXES twice? Could you please share your code if it works for you.
I'm using some code like below (not full):
ax_id = app.UIAxes;
an = animatedline(ax_id, 'MaximumNumPoints',1000);
...
for i=1:1:100000
addpoints(an, x(i), y(i));
if (rem(i,100) == 0)
if i>=1000
xlim (ax_id, [i-1000+1 i]);
else
xlim (ax_id, [1 i]);
end
drawnow limitrate
end
end
Here are some timings:
  • No plotting: 60s
  • Standard Figure + axes: 63s
  • UIaxes only: 84s
I hope this will be resolved in the future - many many threads with complaints, but nothing has been done.

Veronica Taurino
Veronica Taurino 2022 年 5 月 2 日
Are there any speed-improvements in Matlab 2021b? If so, I still struggle to find it by myself

martin nguyen
martin nguyen 2023 年 12 月 5 日
編集済み: martin nguyen 2023 年 12 月 5 日
Hello everybody,
I have found a way to improve the speed of interactions with a uifigure/uiaxe application. This is not optimal but for me, it does the trick. The solution is to open a figure very small at the start of the application. The figure is in the left bottom corner of my application and I can minimize it (it is working minimized or not).
And all you have to do is to make sure that the figure remains while you are on your application. I did a bit of code to make sure the figure cannot be deleted by clicking on the cross and I make sure it is deleted when I close the application. In my application, I display meshes and the interactions with the pointer are now far better with the figure opened.
I guess, when I open the figure, the uifigure inherit some properties of the figure and that could be the reason, this is faster but I'm not sure.
Regards
Martin Nguyen
  2 件のコメント
Eduardo Vicente Wolf Trentini
Eduardo Vicente Wolf Trentini 2023 年 12 月 5 日
Let me see if I understand correctly. Does your issue improve if you have another figure open? Here's a video of my application, and you can see that even with another figure open, the response time still remains very slow.
martin nguyen
martin nguyen 2023 年 12 月 7 日
編集済み: martin nguyen 2023 年 12 月 7 日
Hello,
Yes but I create my figure in the startup function of my application, I don't know if you did this or you opened a figure from the Matlab console. Because when my app is running and I open a figure from the Matlab console it doesn't work, it has to be launched within the app. I create and open the figure in the startup function of my app then I minimized it and it works, the response time on my uiaxes in my app are far better.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop uifigure-Based Apps についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by