在Matlab中按剧情序列创建电影 [英] Creating movie by sequence of plots in matlab

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

问题描述

我在下面的问题中问这个问题

I'm asking this question in the following of the question

问题和答案

运行答案代码后,您可以按情节序列观看电影.有没有办法将剧情序列保存为电影?

After running the answer code, you can see a movie by sequences of plots. Is there a way to save the sequence of plots as movie?

任何答案都值得赞赏.

推荐答案

您可以使用

You can create a video of a plot by using the VideoWriter object in the following steps:

1)创建并打开视频对象(同时指定视频名称)

1) Create and open the video object (also specifying the name of the video)

 vidObj = VideoWriter('SIN_X_COS_X.avi');

2)在绘图循环中,使用plot后获得当前帧="nofollow noreferrer"> getframe 函数

2) in the plotting loop, get the current frame after the the call to plot with the getframe function

currFrame = getframe;

3)在视频文件中写入当前帧

3) write the curent frame in the video file

writeVideo(vidObj,currFrame);

4)在绘图循环结束时关闭视频对象

4) close the video object at the end of the plotting loop

close(vidObj);

close(vidObj);

关于您所指的答案的代码,您只需要在步骤描述中指定的位置添加以上语句即可.

With respect to the code of the answer you are referring to, you just have to add the above statements, in the location mentined in the step description.

在下面,您可以找到建议的方法的一种可能的实现方式.

In the following you can find a possible implementation of the proposed approach.

% Generate some data
t=0:.01:2*pi;
sin_x=sin(t);
cos_x=cos(t);
% Open a figure and crate the axes
figure
axes;
%
% STEP 1:
%
% Create and open the video object
vidObj = VideoWriter('SIN_X_COS_X.avi');
open(vidObj);
%
% Loop over the data to create the video
for i=1:length(t)
   % Plot the data
   h(1)=plot(t(i),sin_x(i),'o','markerfacecolor','r','markersize',5);
   hold on
   plot(t(1:i),sin_x(1:i),'r')
   plot(t(1:i),cos_x(1:i),'b')
   h(2)=plot(t(i),cos_x(i),'o','markerfacecolor','b','markersize',5);
   set(gca,'xlim',[0 2*pi],'ylim',[-1.3 1.3])
   %
   % STEP 2
   %
   % Get the current frame
   currFrame = getframe;
   %
   % STEP 3
   %
   % Write the current frame
   writeVideo(vidObj,currFrame);
   %
   delete(h)
end
%
% STEP 4
%
% Close (and save) the video object
close(vidObj);

希望这会有所帮助,

Qapla'

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

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