2017-04-17 3 views
0

Wenn ich diese Funktion aufrufen, bewegen sich die Achsen mit dem Plot. Wie kann ich das verhindern? Ich habe versucht, xlim und ylim vor der Funktion im Befehlsfenster, aber das hat nicht funktioniert.Matlab: Animation mit festen Achsen zeichnen

Mein Code ist:

function h = plootwithanimation(x,y) 

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

Antwort

1

fixing the bounds Versuchen Sie, die axis Funktion:

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

Sie die Grenzen durch die Verwendung xlim und ylim beheben können, wie Sie versucht, aber Plotten ignorieren, was Sie setzen die Achsen vor dem Aufruf plot.

Sie sollten, anstatt sie nach dem Grund verwenden

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 
Verwandte Themen