use*_*758 5 plot animation octave
我正在使用 Octave 编写一个脚本来绘制不同时间段的函数。我希望制作一个情节动画,以便看到随时间的变化。
有没有办法保存每个时间点的每个图,以便可以组合所有图来创建此动画?
这有点混乱,但您可以执行以下操作(此处适用于 Octave 4.0.0-rc2):
x = (-5:.1:5);
for p = 1:5
plot (x, x.^p)
print animation.pdf -append
endfor
im = imread ("animation.pdf", "Index", "all");
imwrite (im, "animation.gif", "DelayTime", .5)
Run Code Online (Sandbox Code Playgroud)
基本上,将所有绘图打印成 PDF,每页一个。然后以图像形式阅读 pdf,并将其以 gif 形式打印回来。这在 Matlab 上不起作用(其 imread 实现无法处理 pdf)。
这将创建一个动画 gif
data=rand(100,100,20); %100 by 100 and 20 frames
%data go from 0 to 1, so lets convert to 8 bit unsigned integers for saving
data=data*2^8;
data=uint8(data);
%Write the first frame to a file named animGif.gif
imwrite(data(:,:,1),'/tmp/animGif.gif','gif','writemode','overwrite',...
'LoopCount',inf,'DelayTime',0);
%Loop through and write the rest of the frames
for ii=2:size(data,3)
imwrite(data(:,:,ii),'/tmp/animGif.gif','gif','writemode','append','DelayTime',0)
end
Run Code Online (Sandbox Code Playgroud)