2017-02-25 42 views

回答

0

您可以通过使用以下步骤VideoWriter对象创建一个情节的视频:

1)创建并打开了视频对象(也指定视频的名称)

vidObj = VideoWriter('SIN_X_COS_X.avi'); 

2)在绘图循环,得到了该呼叫之后当前帧plotgetframe功能

currFrame = getframe; 

3)WRI TE上CURENT帧在视频文件

writeVideo(vidObj,currFrame); 

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

接近(vidObj)的端部;

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

在下面,您可以找到建议方法的可能实施。

% 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”