我正在使用 contourf 来生成波传播动画。对于for循环的每次迭代,我只为矩阵中的一个范围着色。然后我将生成的图像动画化为gif。当我添加图像作为波浪动画的背景时,随着动画的进行,动画会保留所有颜色范围。
这里'部分代码
filename = 'heart18a.gif';
img = imread('heart_18.jpg');
min_x = 0;
max_x = 661;
min_y = 0;
max_y = 749;
%plot the background and Z points
hold on
for n = min(z):1:max(z),
imagesc([min_x max_x], [min_y max_y],img);
plot(x,y,'.');
end
hold off
i = 1;
%loop and isomap generation
for n =1:1:14,
hold on
contourf(XI,YI,ZI,[n n+1],'linecolor','black')
colormap (jet)
caxis ([-10 50])
alpha(0.5);
%set the y-axis back to normal.
%set(gca,'ydir','normal');
hold off
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
i = i + 1;
end
谢谢