博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MATLAB 动图绘制、保存
阅读量:4691 次
发布时间:2019-06-09

本文共 2108 字,大约阅读时间需要 7 分钟。

动图有gif格式和视频的avi格式。

1、sin(x)动图

clear allh = animatedline;%动画线axis([0 4*pi -1 1])box onx = 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

  

2、

close all; clear all;%创建avi文件对象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);    %加入avi对象中    writeVideo(aviobj,F);         %转成gif图片,只能用256色    im = frame2im(F);    [I,map] = rgb2ind(im,256);    %写入 GIF89a 格式文件        if k == 1;        imwrite(I,map,'test.gif','GIF', 'Loopcount',inf,'DelayTime',0.1);    else        imwrite(I,map,'test.gif','GIF','WriteMode','append','DelayTime',0.1);    end    endclose(fig);%关闭avi对象 close(aviobj);

  

 3、

clear allclose allmov=VideoWriter('mult_1.avi');open(mov);N=50;om=0.1;X = linspace(0,12.4,N);Y = 0*X;Z2= 0*X;for it=1:100       Z = cos(X-it*om);   Y2= cos(X-it*om);   stem3(X,Y,Z,'r','fill')   hold on   stem3(X,Y2,Z2,'k','fill')   hold on;   line(X,Y,Z2);   for ix=1:N      hold on;      plot([X(ix) X(ix)],[0 Y2(ix)],'k');   end;   hold off   view(-25,30);   xlim([X(1) X(end)]);   ylim([-1 1])   zlim([-1 1])   set(gcf,'Color',[1 1 1],'nextplot','replacechildren', 'Visible','off')   axis off   FF=getframe(gcf);   % With "VideoWriter" use "writevideo" to add frames to the video   writeVideo(mov,FF);   im = frame2im(FF);    [I,map] = rgb2ind(im,256);    %写入 GIF89a 格式文件        if it == 1;        imwrite(I,map,'test.gif','GIF', 'Loopcount',inf,'DelayTime',0.1);    else        imwrite(I,map,'test.gif','GIF','WriteMode','append','DelayTime',0.1);    end    end;% Close the video fileclose(mov);

  

 

转载于:https://www.cnblogs.com/ruo-li-suo-yi/p/8312880.html

你可能感兴趣的文章
试用cmd markdown
查看>>
WPF学习之路由事件
查看>>
HDFS 通信接口
查看>>
oracle函数 NLS_INITCAP(x[,y])
查看>>
使用 /proc 文件系统
查看>>
Android Launcher3 开启旋转后有部分任务在旋转后会显示出来
查看>>
团队作业4——第一次项目冲刺(Alpha版本)
查看>>
Java虚拟机工作原理详解 (一)
查看>>
jQuery $.each用法
查看>>
iOS最好用的弹出框
查看>>
大数据 Spark 架构
查看>>
大数据中mapreduce的核心,shuffle的理解,以及在shuffle中的优化问题
查看>>
ORA-12545:因目标主机或对象不存在,连接失败的解决办法
查看>>
用户体验的13条金科玉律
查看>>
20 个高质量响应式的 HTML/CSS 网站模板
查看>>
The best manual of how to use "The easiest Xdebug" addon for Firefox
查看>>
PAC学习框架
查看>>
Android下各个按键对应的key code
查看>>
文本编辑器Vim/Neovim任意代码执行漏洞(CVE-2019-12735)
查看>>
for each in for in for of
查看>>