我需要类似 this 的东西,但是我有很多描述二维电场随时间变化的矩阵。所以我希望矩阵可视化相互替换,以获得视频
最佳答案
我想给您一个示例代码,用于从一系列绘图生成动画 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)
关于matlab - 如何在同一 Canvas 上连续可视化matlab中的多个矩阵以制作视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10671724/