2017-04-17 107 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