在 linux 中播放 .avi
Playing .avi in linux
我写了一段代码,可以在 Matlab 中保存两部电影。问题是,电影 "graphh.avi" 也是由第一部电影 ("chert") 组成的。我希望它只显示图表而不是第一个保存的电影 ("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);
调用时使用数字句柄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);
我写了一段代码,可以在 Matlab 中保存两部电影。问题是,电影 "graphh.avi" 也是由第一部电影 ("chert") 组成的。我希望它只显示图表而不是第一个保存的电影 ("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);
调用时使用数字句柄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);