如何使用MATLAB上的一系列图生成视频文件? [英] How to generate a video file using a series of plots on MATLAB?

查看:964
本文介绍了如何使用MATLAB上的一系列图生成视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在循环中创建的一堆绘图拼接在一起,形成一个视频文件.我已经在这里待了几个小时,但是没有运气.这是我尝试使用VideoWriter函数创建视频的最小工作示例.我总是收到一个错误消息,说我的帧无法复制到视频对象中. .

I'm trying to stitch together a bunch of plots I created within a loop into a single video file. I've been at this for several hours, but had no luck. Here is my minimum working example where I attempt to use the VideoWriter function to create a video. I always get an error saying my frame(s) can't be copied into the video objects. Grr.

这是我的最低工作示例:

Here is my minimum working example:

n=(1:50)*2*pi;
for t = 1:1000
    Y = sin(n*50/t);
   plot(Y);     %plot shows a sine wave with decreasing frequency

   F(t) = getframe; %I capture the plot here


end

writerObj = VideoWriter('test2.avi'); %Attempt to create an avi
open(writerObj);
for t= 1:time

    writeVideo(writerObj,F(t))

end

close(writerObj);

推荐答案

您缺少恒定的图像高度.您可以通过例如ylim:

You are missing a constant height of images. You can guarantee it by, e.g., ylim:

time = 100;
for t = 1:time
   fplot(@(x) sin(x*50/t),[0,2*pi]);  % plot
   ylim([-1,1]);                      % guarantee consistent height
   F(t) = getframe;                   % capture it
end

writerObj = VideoWriter('test2.avi');
open(writerObj);
writeVideo(writerObj, F)
close(writerObj);

我进一步将您的离散图替换为连续"图(使用fplot).

I have further replaced your discrete plot by a "continuous" one (using fplot).

这篇关于如何使用MATLAB上的一系列图生成视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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