matlab plot 动态演化

time = 0:0.05:2*pi;

x = 6*(1-cos(time));
y = sin(time);
z = 7*exp(-(time-pi).^2);

% 如何把随着时间的演化也体现出来呢?
%if you want to animate it 动态轨迹
for i=1:length(x)
    plot3(x(i),y(i),z(i),'*r');
    ylim([-1 1]);
    xlim([0 15]);
    zlim([0 8]);
    hold on;
    pause(0.1);
end

xlabel('x(meters)');
ylabel('y(meters)');
zlabel('Altitude(meters)');

还有一种绘制动图的方式:

clc;
close all;
x1=0;s=0.2;%确定起始点和增量
nframes=50;%确定总动画帧数
for k=1:nframes
    x1=x1+s;%确定画图时的横坐标终止值x1
    x=0:0.01:x1;
    y=sin(x);
    plot(x,y);
    axis([0 2*pi   -1.2 1.2]);%坐标轴的范围
    m(k)=getframe;%将当前图形存入矩阵m中
end
movie(m,3)%重复3此播放动画

还有一种方案,直接将结果存成gif文件:

 ---------------------------------------------

官方教程,绘制动态曲线:

h = animatedline;
axis([0 4*pi -1 1])
x = linspace(0,4*pi,2000);

for k = 1:length(x)
    y = sin(x(k));
    addpoints(h,x(k),y);
    drawnow
end

posted @ 2022-03-20 21:35  bH1pJ  阅读(9)  评论(0编辑  收藏  举报