1

我正在学习用 Matlab 制作电影。我从互联网上处理了这段代码来制作电影。我正在使用 OS X Mavericks 和 Matlab 2013a。我通常停靠图形窗口。当我运行代码时,我可以完美地看到动画。当我通过使用 movie2aviVideoWriter命令保存电影时。它不会以全帧图形录制电影。相反,我看到了一些图形窗口和我的 Matlab 桌面视图。谁能帮我这个?

 clear; 
close all;

% Creates a 2D Mesh to plot surface
x=linspace(0,1,100);
[X,Y] = meshgrid(x,x);

N=100; % Number of frames
for i = 1:N
% Example of plot 
Z = sin(2*pi*(X-i/N)).*sin(2*pi*(Y-i/N));
surf(X,Y,Z)
% Store the frame   
M(i)=getframe(gca); % leaving gcf out crops the frame in the movie.


end 

% myVideo = VideoWriter('wavemotion.avi');
% open(myVideo);
% writeVideo(myVideo,M)
% close(myVideo)


% Output the movie as an avi file
%movie2avi(M,'WaveMovie.avi');
4

1 回答 1

0

根据 和 的文档VideoWritermovie2avi您需要在代码中添加更多说明。

首先,您需要设置渲染器以获得良好的显示效果,并设置下一个绘图将仅重置子级而不是整个轴的轴:

set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');

还有一个预先分配帧缓冲区的建议:

M(N) = struct('cdata',[],'colormap',[]);

最后,您只需要在getframe没有任何gca参数的情况下调用,默认参数也是如此。

在我的电脑上(使用 Matlab 2013b),通过这些修改和使用VideoWriter,它工作正常。使用movie2avi,则无法正常工作;我想我需要指定一个压缩编解码器来解决这个问题。

于 2014-07-08T08:54:44.163 回答