2017-04-17 106 views
0

当我调用这个函数时,轴正在随着绘图移动。我怎样才能阻止这种情况发生?我试图在命令窗口中的函数之前放置xlimylim,但这不起作用。Matlab:使用固定轴绘制动画

我的代码是:

function h = plootwithanimation(x,y) 

    for h = 1:length(x) 
     plot(x(h),y(h),'*') 
     pause(1) 
     hold on 
    end 

回答

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 
0

您可以通过使用xlimylim你尝试过解决这个界限,但密谋会忽略你设置的轴在致电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