matlab 곡선을 쉽게 그리는 애니메이션 효과

2567 단어 matlab코드
다음 프로그램은 애니메이션 효과를 그릴 수 있다.매우 실용적입니다. 문법에 주의하십시오. 라인과 유사하지만, 앞의 두 개는 반드시 xdata와 ydata입니다.
function h=animline(xdata, ydata, varargin)
% input:
% varargin: properties in line or
%           time: time from [xdata(k),ydata(k)] to [xdata(k+1),ydata(k+1)];(        )
%           gradient: gradual change (    ,         )
% xdata,ydata: vector
% grammar:
%     h=animline(xdata, ydata,'Parent',haxes ,'Gradient',10,'Time',1,'Marker','*');

time = 1;
gradient=1;
c={};            %    Line 
for i=1:2:length(varargin)
    property=varargin{i};
    value=varargin{i+1};
    switch(lower(property));
        case 'time'
            time=value;
        case 'gradient'
            gradient=value;
        otherwise
            c=[c,property,value];
    end
end

n=length(xdata);
t=time/(gradient);
for k=1:n-1
    h=line( 'XData', xdata(1:k),'YData', ydata(1:k) ,c{:});
    pause(t); delete(h);
    xk=xdata(k); yk=ydata(k);
    dx=(xdata(k+1)-xk)/gradient; dy=(ydata(k+1)-yk)/gradient; % step length
    for g =1:gradient-1
        h=line( 'XData', [xdata(1:k),xk+dx*g],'YData', [ydata(1:k),yk+dy*g] ,c{:});
        pause(t); delete(h);
    end
end

h=line('XData', xdata,'YData', ydata ,c{:});

다음은 다른 버전입니다.drawnow 함수를 사용했습니다.
function h=animline(xdata, ydata, varargin)
% input:
% varargin: properties in line or
%           time: time from [xdata(k),ydata(k)] to [xdata(k+1),ydata(k+1)];
%           gradient: gradual change
% xdata,ydata: vector
% grammar:
%     h=animline(xdata, ydata,'Parent',haxes ,'Gradient',10,'Time',1,'Marker','*');

time = 1;
gradient=1;
c={};
for i=1:2:length(varargin)
    property=varargin{i};
    value=varargin{i+1};
    switch(lower(property));
        case 'time'
            time=value;
        case 'gradient'
            gradient=value;
        otherwise
            c=[c,property,value];
    end
end

n=length(xdata);
t=time/(gradient);
h=line( 'XData', [],'YData', [] ,c{:});
for k=1:n-1
    set(h, 'XData', xdata(1:k),'YData', ydata(1:k));
    drawnow; pause(t);
    xk=xdata(k); yk=ydata(k);
    dx=(xdata(k+1)-xk)/gradient; dy=(ydata(k+1)-yk)/gradient; % step length
    for g =1:gradient-1
        set(h, 'XData', [xdata(1:k),xk+dx*g],'YData', [ydata(1:k),yk+dy*g]);
        drawnow; pause(t); 
    end
end

set(h,'XData', xdata,'YData', ydata);drawnow;

좋은 웹페이지 즐겨찾기