我需要这样的东西,但我有很多描述二维电场随时间变化的矩阵。所以我希望矩阵可视化相互替换,以获取视频
问问题
589 次
1 回答
2
我想给你一个示例代码,以从一系列绘图中生成动画 gif。您可以修改绘图以生成您喜欢的任何内容;例如,您的链接中的那个。
gifOutputName = 'sample.gif';
%# As an example, let us draw a 3-D plot
%# You can generalize it to anything you like
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
for j = 1:20
surf(sin(2*pi*j/20)*Z,Z)
%# Grab the current frame
RGB = frame2im(getframe(gcf));
%# Reduce it to 256 colors since it's gonna be GIf image
[IND, map] = rgb2ind(RGB, 256);
if j == 1 % Vreate in the first step
%# 'LoopCount' indicates how many times the animation will play,
%# Inf states infinity. Refer to "GIF-Specific Parameters" in the
%# documentation.
imwrite(IND, map, gifOutputName, 'gif', 'LoopCount', Inf);
else %# Otherwise, append it to the previous
imwrite(IND, map, gifOutputName, 'gif', 'WriteMode', 'append');
end
end
close %# Close the figure
(来源:ismailari.com)
于 2012-05-20T12:22:54.083 回答