2014-04-29 1 views
3

함수 dx/dt의 애니메이션을 플로팅하고 축을 설정했지만 애니메이션이 실행되면 축이 플롯에 따라 동적으로 변경됩니다. 이 문제를 어떻게 수정합니까?Matlab에서 애니메이션을 플롯 할 때 축이 동적으로 변경되지 않게하려면 어떻게해야합니까?

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 

답변

3

는 간단히 "축"명령과 "음모"명령의 순서를 반대로. "plot"앞에 "axis"를 사용하면 "plot"이 기본 축으로 "axis"명령을 덮어 씁니다. 이 두 줄을 전환하면 문제가 해결됩니다.

그러나 개별 지점을 애니메이션으로 만들려면 깔끔한 애니메이션에 대한 경이로움을 다루는 "설정"명령이 있습니다. 이 체크 아웃 :

% 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 

http://www.mathworks.com/matlabcentral/newsreader/view_thread/270439

+0

을 나는이 "사각형"및 "입력"또는 "축 동일하게"사용 "축 같은 명령과 같은 경우이다 플롯보다 다른 추가해야한다고 생각 ([ xmin xmax ymin ymax]) "모두! 감사합니다 :) – kiyarash

+0

원한다면 내 대답을 편집 할 수 있습니다. – Blairg23

관련 문제