2018-09-19 Matlab 绘制动态图

2018-11-09  本文已影响0人  gracebeibei

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
上一篇下一篇

猜你喜欢

热点阅读