24小时热门版块排行榜    

CyRhmU.jpeg
查看: 743  |  回复: 6

xuanyz

木虫 (小有名气)

[求助] matlab动态绘图并存储为gif和avi但图片和avi文件不动态显示已有1人参与

请问高手
我用matlab动态绘图并存储为gif和avi但图片和avi文件不动态显示:
具体程序如下:
clear;clc; %清除所有数据

nFrames = 20;

% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],...
                        'colormap', []);

% Create movie.
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
for k = 1:nFrames
   surf(sin(2*pi*k/20)*Z,Z)
   mov(k) = getframe(gcf);

if k==1
[I,map]=rgb2ind(mov(k).cdata,256);
imwrite(I,map,'out.gif','DelayTime',.1,'LoopCount',Inf)    %gif图像无限循环
else
[I,map]=rgb2ind(mov(k).cdata,256);
imwrite(I,map,'out.gif','WriteMode','append','DelayTime',0.1)    %添加到图像
end


   end
% Create AVI file.
movie2avi(mov, 'myPeaks.avi', 'compression', 'None');
还请高手指点?
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cooooldog

铁杆木虫 (著名写手)

ส็็็

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
xuanyz: 金币+30, ★★★★★最佳答案, 最佳答案,感谢感谢 2014-11-15 12:18:45
CODE:
close all
clear all
clc; %

nFrames = 50;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],'colormap', []);

% Create movie.
figure('color','white');
Z = peaks(150); surf(Z,Z,'edgecolor','none');
view(3);
axis vis3d tight equal off;
v = axis;
% set(gca,'nextplot','replacechildren');
for k = 1:nFrames
    clf;
    surf(1.5*sin(2*pi*k/20)*Z,Z,'edgecolor','none');   
    axis(v);
    axis off
    camlight;
    lighting phong
    mov(k) = getframe;
    [Inx,cmap]=rgb2ind(mov(k).cdata,256);
    if k==1
        imwrite(Inx,cmap,'testoutx.gif','gif','DelayTime',0.25,'LoopCount',Inf)    %gif
    else
        imwrite(Inx,cmap,'testoutx.gif','gif','WriteMode','append','DelayTime',0.25)    %
    end
end
% Create AVI file.
movie2avi(mov, 'myPeaks.avi', 'compression', 'None');

ส็็็็็็็็็็็็็็็็็็็็
2楼2014-11-14 20:39:15
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cooooldog

铁杆木虫 (著名写手)

ส็็็

你这代码如果在R2013a以后版本应该没大问题
ส็็็็็็็็็็็็็็็็็็็็
3楼2014-11-15 08:34:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xuanyz

木虫 (小有名气)

引用回帖:
2楼: Originally posted by cooooldog at 2014-11-14 20:39:15
close all
clear all
clc; %

nFrames = 50;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],'colormap', []);

% Create movie.
figure('color','white');
Z = peaks(150); surf( ...

感谢楼主了,可否简单解释下我的程序为何有bug
4楼2014-11-15 12:19:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xuanyz

木虫 (小有名气)

请问这个跟操作系统有关吗?同样的这个程序,我在同样是安装有matlab2010b的win7普通版和旗舰版的两台电脑上均可以运行,但在win7普通版上运行的结果存储的文件为静态
5楼2014-11-15 12:23:12
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cooooldog

铁杆木虫 (著名写手)

ส็็็

引用回帖:
5楼: Originally posted by xuanyz at 2014-11-15 12:23:12
请问这个跟操作系统有关吗?同样的这个程序,我在同样是安装有matlab2010b的win7普通版和旗舰版的两台电脑上均可以运行,但在win7普通版上运行的结果存储的文件为静态

应该是Matlab 2010b的问题吧;
你是同样的Matlab 2010b 分别在win 7不同系统下结果不一样吗?

估计是getframe有小bug, 当然你的Matlab 2010b的来源及安装情况如何呢?
ส็็็็็็็็็็็็็็็็็็็็
6楼2014-11-15 13:08:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xuanyz

木虫 (小有名气)

再次感谢了,不过你改过的程序确实可以运行,多谢了
7楼2014-11-16 15:50:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 xuanyz 的主题更新
信息提示
请填处理意见