Matlab绘制动态图的两种方式(参考)

 第一种方式

close all;
clear all;
clc;
clf;
xlabel('X轴');
ylabel('Y轴');
box on;
axis([-2,2,-2,2]);
axis equal;
pause(1);
h=line(NaN,NaN,'marker','o','linesty','-','erasemode','none');
t=6*pi*(0:0.02:1);
for n=1:length(t)
    set(h,'xdata',2*cos(t(1:n)),'ydata',sin(t(1:n)));
    pause(0.05);
    frame=getframe(gcf);
    imind=frame2im(frame);
    [imind,cm] = rgb2ind(imind,256);
    if n==1
         imwrite(imind,cm,'test.gif','gif', 'Loopcount',inf,'DelayTime',1e-4);
    else
         imwrite(imind,cm,'test.gif','gif','WriteMode','append','DelayTime',1e-4);
    end
end

效果图

close all;
clear all;
clc;
clf;
%白色背景
axis([-2,2,-2,2]);
xlabel('X轴');
ylabel('Y轴');
%四周的边框
box on;
%绘图区域
t=0:0.02:10;  
Nt=size(t,2);
x=2*cos(t(1:Nt));
y=sin(t(1:Nt));
%循环绘图
for i=1:Nt;
    cla;
    hold on;
    plot(x,y)
    plot(x(i),y(i),'o');
    frame=getframe(gcf);
    imind=frame2im(frame);
    [imind,cm] = rgb2ind(imind,256);
    if i==1
         imwrite(imind,cm,'test.gif','gif', 'Loopcount',inf,'DelayTime',1e-4);
    else
         imwrite(imind,cm,'test.gif','gif','WriteMode','append','DelayTime',1e-4);
    end
end

效果图

 

 

你可能感兴趣的:(MATLAB)