Matlab 绘制动态图
drawnow 更新图窗并处理回调
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
test01.gif
将动态图保存为gif
filename='test01.gif';
Fig=figure;
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
frame=getframe(Fig);
im=frame2im(frame);
[imind,cm]=rgb2ind(im,256);
if k==1
imwrite(imind,cm,filename,'gif','WriteMode','overwrite','Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.02);
end
end
网友评论