不能在MATLAB中使用movie2avi

时间:2015-10-16 15:03:52

标签: matlab avi movie

我正在尝试在MATLAB中使用movie2avi函数。我只是在MATLAB R2015a中复制示例程序:

nFrames = 20;

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

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

% Create AVI file.
movie2avi(mov, 'myPeaks.avi', 'compression', 'None');

但会显示错误消息:

  

使用avi意外错误时出错。原因:无法打开文件。

     

audiovideo.internal.aviwriter中的错误(第168行)                 aviobj.FileHandle = avi('open',filename);

     

movie2avi中的错误(第63行)avimov =   audiovideo.internal.aviwriter(文件名,varargin {:});

     

MakeMovie中的错误(第36行)movie2avi(mov,'myPeaks.avi',   '压缩','无');

这里有什么问题?请帮忙。

1 个答案:

答案 0 :(得分:0)

我有同样的问题,在使用movie2avi创建新电影和我的问题之前,只需删除上一个Object的历史记录 解决了。​​在你的代码中:

    nFrames = 20;

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

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

    if(isobject(aviobj))
    clear mov % if mov exist
    end

   % Create AVI file.
   movie2avi(mov, 'myPeaks.avi', 'compression', 'None');

    clear mov