美文网首页
2018-09-19 Matlab 绘制动态图

2018-09-19 Matlab 绘制动态图

作者: gracebeibei | 来源:发表于2018-11-09 15:27 被阅读0次

    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
    

    相关文章

      网友评论

          本文标题:2018-09-19 Matlab 绘制动态图

          本文链接:https://www.haomeiwen.com/subject/zpgbnftx.html