在linux中播放.avi

时间:2017-03-27 08:36:42

标签: matlab matlab-figure matlab-guide avi

我编写了一个代码,用于在Matlab中保存两部电影。问题在于,电影" graphh.avi"由第一部电影(" rt")组成。我希望它只显示图形而不是第一个保存的电影(" chert.avi")。 有人可以帮忙吗?任何答案都非常感谢。

clear all
close all
cla
h = plot(x, y, '.g', 'MarkerSize', 10);
set(gca,'Color',[0 0 0]);
 set(gcf,'doublebuffer','on')
set(gca,'YTick',[]);
set(gca,'XTick',[]);
plot(x,y,'.g','markersize',10)
drawnow
currFrame = getframe;
writeVideo(vidObj,currFrame);
h = plot(x, y, '.g', 'MarkerSize', 10);
drawnow

hist(blocksize)
currFrame = getframe;
writeVideo(vid,currFrame);
end
close(vidObj);
close(vid)

第一个答案后的代码如下所示。问题解决但现在还有另一个问题:带有绿点的黑色电影变得如此混乱。

clear all
close all
l = 20;
r = 3;
v = 0.5;
dt = 1;
nn=200;
figure(h1); % set figure 1 as current figure
h = plot(x, y, '.g', 'MarkerSize', 10);
set(gca,'Color',[0 0 0]);
set(gcf,'doublebuffer','on')
set(gca,'YTick',[]);
set(gca,'XTick',[]);
plot(x,y,'.g','markersize',10)
drawnow
currFrame = getframe(h1); % gets only figure 1
writeVideo(vidObj,currFrame);
 h = plot(x, y, '.g', 'MarkerSize', 10);
drawnow
figure(h2); % set figure 2 as current figure
hist(blocksize)
currFrame = getframe(h2); % gets only figure 2
writeVideo(vid,currFrame);
end
close(vidObj);
close(vid);

1 个答案:

答案 0 :(得分:0)

调用getframe时使用数字句柄。看看我如何修改你的代码:

% some code...
vvy = v.*sin(tetha);
h1 = figure('Color',[0 0 0])
axis([0 l 0 l])
% some more code...
h2 = figure
hold on
vid = VideoWriter('graphh.avi');
% and more code...
% for loop
    figure(h1); % set figure 1 as current figure
    % plot whatever on this figure
    currFrame = getframe(h1); % gets only figure 1
    writeVideo(vidObj,currFrame);
    % blah blah...
    figure(h2); % set figure 2 as current figure
    % plot whatever on this figure
    currFrame = getframe(h2); % gets only figure 2
    writeVideo(vid,currFrame);
% end of loop

修改

在修改后的代码中,您无缘无故地连续三次调用h = plot(x, y, '.g', 'MarkerSize', 10);,因此请将其删除。你遇到的问题源于另外一组点另外到前一个点,所以轴充满了点。一个解决方案是使用set(h,'XData',x,'YData',y),如下所示:

figure(h1); % set figure 1 as current figure
set(gca,'Color',[0 0 0]);
set(gcf,'doublebuffer','on')
set(gca,'YTick',[]);
set(gca,'XTick',[]);
if exist('h','var') && ishandle(h) % if handle exists just change coordinates
    set(h,'XData',x,'YData',y)
else  % only for the first time you plot that
    h = plot(x, y, '.g', 'MarkerSize', 10);
end
drawnow
currFrame = getframe(h1); % gets only figure 1
writeVideo(vidObj,currFrame);