Matlab制作gif或者avi动态图

    xiaoxiao2023-10-31  150

    动图一般有两种格式.gif以及.avi,都能拥有更好的展示效果

    %% avi close all; clear all; aviobj = VideoWriter('test.avi','Uncompressed AVI'); open(aviobj) t = linspace(0,2.5*pi,40); fact = 10*sin(t); fig=figure; [x,y,z] = peaks; for k=1:length(fact) h = surf(x,y,fact(k)*z); axis([-3 3 -3 3 -80 80]) axis off caxis([-90 90]) F = getframe(fig); writeVideo(aviobj,F); im = frame2im(F); [I,map] = rgb2ind(im,256); if k == 1 imwrite(I,map,'test1.gif','GIF', 'Loopcount',inf,'DelayTime',0.1); else imwrite(I,map,'test1.gif','GIF','WriteMode','append','DelayTime',0.1); end end close(fig); close(aviobj);

    %% gif clear all h = animatedline;%动画线 axis([0 4*pi -1 1]) box on x = linspace(0,4*pi,200); for k = 1:length(x) y = sin(x(k)); addpoints(h,x(k),y);%将数据添加到动画线中 drawnow%画出动画线 f=getframe(gcf); imind=frame2im(f); [imind,cm] = rgb2ind(imind,256); if k == 1 imwrite(imind,cm,'test.gif','GIF', 'Loopcount',inf,'DelayTime',1); else imwrite(imind,cm,'test.gif','GIF','WriteMode','append','DelayTime',1); end end

    甚至也可以将.tif文件用这种方法做成动图

    最新回复(0)