在Matlab中绘制动画时,如何防止轴动态变化?
我正在绘制函数dx/dt的动画,我已经设置了轴,但是当动画运行时,轴会根据绘图动态变化。如何解决此问题在Matlab中绘制动画时,如何防止轴动态变化?,matlab,animation,plot,axes,Matlab,Animation,Plot,Axes,我正在绘制函数dx/dt的动画,我已经设置了轴,但是当动画运行时,轴会根据绘图动态变化。如何解决此问题 clear all; %Equation variables: s = 0; r = 0.4; %axes limits: xmin = 0; xmax = 2; ymin = -.05; ymax = .2; %s limits: smin = 0; smax = 1; s_steps = 100; %our x-space: x = linspace(xmin, xmax, 100
clear all;
%Equation variables:
s = 0;
r = 0.4;
%axes limits:
xmin = 0;
xmax = 2;
ymin = -.05;
ymax = .2;
%s limits:
smin = 0;
smax = 1;
s_steps = 100;
%our x-space:
x = linspace(xmin, xmax, 100);
%Let's try different s-values and plot as an animation:
for s=linspace(smin, smax, s_steps)
counter = counter + 1;
%dx/dt:
dxdt = s - r.*x + (x.^2)./(1 + x.^2);
figure(1),
subplot(2,1,1)
axis([xmin xmax ymin ymax]);
plot(x, dxdt);
title(strcat('S-value:', num2str(s)));
hold on;
y1 = line([0 0], [ymin ymax], 'linewidth', 1, 'color', [0.5, 0.5, 0.5], 'linestyle', '--');
x1 = line([xmin xmax], [0 0], 'linewidth', 1, 'color', [0.5, 0.5, 0.5], 'linestyle', '--');
hold off;
end
只需颠倒“轴”命令和“绘图”命令的顺序即可。在“打印”之前使用“轴”时,“打印”将使用默认轴替代“轴”命令。切换这两条线路可以解决问题 但是,如果您想为单个点设置动画,还有一个“set”命令,它可以为整洁的动画创造奇迹。看看这个:
% data (Lissajous curves)
t = linspace(0,2*pi,50) ;
x = 2 * sin(3*t) ;
y = 3 * sin(4*t) ;
figure % force view
h = plot(x(1),y(1),'b-',x(1),y(1),'ro') ;
pause(0.5) ;
axis([-3 3 -4 14]) ; % specify a strange axis, that is not changed
for ii=2:numel(x),
% update plots
set(h(1),'xdata',x(1:ii),'ydata',y(1:ii)) ;
set(h(2),'xdata',x(ii),'ydata',y(ii)) ;
pause(0.1) ; drawnow ; % visibility
end
我想我应该补充一点,除了plot之外,对于像“rectangle”和“fill”甚至“axis equal”这样的命令,在所有这些命令之后使用“axis”([xmin-xmax-ymin-ymax]),情况都是一样的!谢谢:)