在屏幕视频上移动一个点

时间:2015-05-30 04:36:17

标签: matlab plot movie

我在弄清楚如何在电影中移动屏幕上的绘图点时遇到了麻烦。所以,让我说一点:

plot(-1.4,-1.4, '.k', 'MarkerSize', 20)

并初始化视频对象

vidObj = VideoWriter('dot.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);

然后如何让点移动到屏幕右侧?

1 个答案:

答案 0 :(得分:0)

要使点在右侧移动,您可以编写一个绘制点的循环;在每次迭代中,点的X坐标递增。

在循环中,您还必须捕获每个帧广告,将其添加到视频文件中。

% Define the initial point's coords
P=[-1.4,-1.4];
% First plot
plot(P(1),P(2), '.k', 'MarkerSize', 20)
% Initialize the video
vidObj = VideoWriter('dot.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);
% set axis properties
set(gca,'nextplot','replacechildren');
% Set xlim (max vaalue to be set according to the desired final position of
% the point)
set(gca,'xlim',[P(1)*2 150]);
% Loop for the point movement: 100 step, each iteration the pont in moved
% to the right of 1x (where x is the unito of measure of the space)
for i = 1:100
   plot(P(1)+i,P(2), '.k', 'MarkerSize', 20)
% Capture the current frame   
   currFrame = getframe;
% Add the current frame to the video file  
   writeVideo(vidObj,currFrame);
end
% Close the video file (stop recording)
close(vidObj);

希望这有帮助。