您沒有提供有關您想製作的電影的足夠信息。製作電影的步驟在此page上突出顯示。關鍵是在循環內調用getframe來生成電影。我正在修改matlab的例子到你的工作中:
clear all
clc
filename='filename.txt';
delimiterIn=' ';
K=importdata(filename,delimiterIn);
% K =load(filename) may also work
nFrames = 20;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],...
'colormap', []);
% Create movie.
plot(K(:,1), K(:,2)); % assumes you are plotting the first two colums
axis tight manual
set(gca,'nextplot','replacechildren');
for k = 1:nFrames
plot(K(:,1), K(:,2)); % assumes you are plotting the first two columns
% the data must somehow change inside this loop
mov(k) = getframe(gcf);
end
% Create AVI file.
movie2avi(mov, 'mydata.avi', 'compression', 'None');
另一個接口是videowriter接口,它存在於更新版本的matlab中。 這是解釋here。並建議比上述步驟。請按照那裏的建議。該頁面很容易遵循。
clear all
clc
filename='filename.txt';
delimiterIn=' ';
K=importdata(filename,delimiterIn);
% K =load(filename) may also work
%Prepare the new file.
writerObj = VideoWriter('movie.avi');
open(writerObj);
% Create movie.
plot(K(:,1), K(:,2)); % assumes you are plotting the first two colums
axis tight manual
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer'); % optional I think
for k = 1:nFrames
plot(K(:,1), K(:,2)); % assumes you are plotting the first two columns
% the data must somehow change inside this loop
frame = getframe(gcf);
writeVideo(writerObj,frame);
end
close(writerObj);
謝謝你讓我試試你的方法。讚賞 – lil 2014-10-04 12:55:26
已經嘗試了上述方法。不過,當我播放.avi文件時,只是創建了一個圖表。不是視頻。任何幫助 – lil 2014-10-04 13:58:56
正如我所評論的那樣,矩陣K列1和2必須在幀間變化,因爲製作電影需要在每個幀處更改數據。你的數據是否在不同的框架之間變化? – Jagte 2014-10-04 15:47:00