一般的读取场的每个时刻的状态,然后输出成视频的 matlab 代码类似这样
video_name = 'zeta_video';
obj = VideoWriter(video_name);
obj.FrameRate = 10;
open(obj);
T_STEP = 1.8e-3;
MAX_STEP = 50000;
OUTPUT_GAP = 500;
x = linspace(0, 8, 513);
y = linspace(0, 8, 513);
[X,Y] = meshgrid(x,y);
levels = linspace(-15, 15, 100);
t_len = MAX_STEP/OUTPUT_GAP;
n = 0:OUTPUT_GAP:MAX_STEP-OUTPUT_GAP;
nImages = length(n);
fig = figure;
%Draw multiple images to display and store each image into a cell array%
for idx = 1:nImages
zeta = csvread(sprintf('./zeta/zeta_%d.csv', n(idx)));
[C,h] = contourf(X, Y, zeta', levels);
clim([-15 15]);
xlim([1 3]);
ylim([3 5]);
colorbar;
set(h,'LineColor','none');
title(sprintf('zeta t = %.2fs', n(idx)*T_STEP));
drawnow
frame = getframe(fig);
writeVideo(obj,frame);
end
close(obj);
后来我想用 scatter 画的时候,发现帧与帧之间的图像重合了
video_name = 'p_video';
obj = VideoWriter(video_name);
obj.FrameRate = 20;
open(obj);
T_STEP = 1.8e-3;
MAX_STEP = 50000;
OUTPUT_GAP = 200;
x = linspace(0, 8, 512);
y = linspace(0, 8, 512);
[X,Y] = meshgrid(x,y);
levels = linspace(-0.001, 0.001, 100);
t_len = MAX_STEP/OUTPUT_GAP;
n = OUTPUT_GAP:OUTPUT_GAP:MAX_STEP-OUTPUT_GAP;
nImages = length(n);
fig = figure;
%Draw multiple images to display and store each image into a cell array%
for idx = 1:nImages
p = csvread(sprintf('./p/p_%d.csv', n(idx)));
p = p';
ax = axes();
scatter(X(:), Y(:), [], p(:), 'filled');
colormap(ax, jet(numel(levels)-1)); % set colormap
caxis(levels([1,end])); % set color range
cb = colorbar();
xlim([1 3]);
ylim([3 5]);
title(sprintf('zeta t = %.2fs', n(idx)*T_STEP));
drawnow
frame = getframe(fig);
writeVideo(obj,frame);
end\
close(obj);
最后发现是我在循环里面创建 axes 的缘故
改成
ax = axes();
%Draw multiple images to display and store each image into a cell array%
for idx = 1:nImages
...
end
就好了