在 MATLAB 中创建电影文件的问题 [英] Problems with movie file creation in MATLAB

查看:24
本文介绍了在 MATLAB 中创建电影文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过在 MATLAB 中循环帧来创建电影.

I attempt to create a movie by looping through frames in MATLAB.

请参阅 http://www.mathworks 上的 mathworks.com 文档.com/help/techdoc/ref/movie.html,我设法为情节制作了动画.但是,当我尝试将电影保存在 avi 文件中时会出现问题.

Refering to mathworks.com documentation at http://www.mathworks.com/help/techdoc/ref/movie.html, I've managed to animate a plot. However, issues arise when I attempt to save the movie in an avi file.

https://stackoverflow 中的 avifileVideoWriter 方法.com/a/8038540/818608,导致同样的错误.

Both the avifile and VideoWriter methods from https://stackoverflow.com/a/8038540/818608, resulted in the same errors.

虽然动画运行良好,但保存的电影仅包含一个固定帧,有时,屏幕截图包含我的后台 Web 浏览器的叠加层.

Although the animation runs fine, the saved movie consists of only one fixed frame, and at times, the screen capture includes an overlay of my background web browser.

提前致谢.

下面是我使用的代码,avi上冻结的帧在下面链接.

Below is the code I used, and the frame that's frozen on the avi is linked below.

Z = peaks; surf(Z); 
axis tight
set(gca,'nextplot','replacechildren');

vid = VideoWriter('myPeaks2.avi');
vid.Quality = 100;
vid.FrameRate = 15;
open(vid);
for k = 1:20 
    surf(sin(2*pi*k/20)*Z,Z)
    writeVideo(vid, getframe(gcf));
end
close(vid);

winopen('myPeaks2.avi')

推荐答案

尝试以下操作:

    f = figure();
    Z = peaks; surf(Z);
    a = axes('Parent',f);
    axis(a,'tight');
    set(a,'nextplot','replacechildren');
    vid = VideoWriter('myPeaks2.avi');
    vid.Quality = 100;
    vid.FrameRate = 15;
    open(vid);
    for k = 1:20
        surf(a,sin(2*pi*k/20)*Z,Z)
        writeVideo(vid, getframe(f));
    end
    close(vid);

    winopen('myPeaks2.avi')

它包含显式句柄 using 而不是隐式.在 Matlab 中造成了许多混乱,因为人们倾向于使用隐式的,例如gcf"、gca",它们本应完全从语言中删除,恕我直言.

It contains explicit handles using instead of implicit. Many chaos is caused in Matlab because people tend to use the implicit ones, like "gcf", "gca" which should have been removed completely from the language, IMHO.

这篇关于在 MATLAB 中创建电影文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆