当我调用此函数时,轴随着图一起移动。我怎么能阻止这种情况发生?我尝试在命令窗口中将xlim
和ylim
放在函数之前,但这不起作用。
我的代码是:
function h = plootwithanimation(x,y)
for h = 1:length(x)
plot(x(h),y(h),'*')
pause(1)
hold on
end
答案 0 :(得分:1)
使用axis
函数尝试fixing the bounds:
function h = plootwithanimation(x,y)
for h = 1:length(x)
plot(x(h),y(h),'*')
axis([0 10 -2 100]) %or whatever you want. This sets 0<x<10 and -2<y<100
pause(1)
hold on
end
答案 1 :(得分:0)
您可以在尝试时使用xlim
和ylim
修复边界,但在调用plot
之前,绘图将忽略您设置轴的任何内容。
你应该在情节之后使用它们
function h = plotwithanimation(x, y, xlims, ylims)
% Also pass in axis limits
% xlims = [x0,x1]
% ylims = [y0,y1]
hold on; % You only have to hold on once around plotting
for h = 1:length(x)
plot(x(h),y(h),'*');
xlim(xlims);
ylim(ylims);
pause(1);
end
hold off; % Good habit so you don't accidentally plot over this figure later