App Slow With UIAxes
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
endHi. 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 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 app designer, plot, axes, delay MATLAB Answers — New Questions