我正在使用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
谢谢