matlab心形動畫(儲存為gif格式)程式
function M
close all
clear
clc
%%初始化
Times=10; [x,y]=meshgrid(-10:0.02:10);
%%
for T=1:Times
z=-(17*x.^2-16*y.*abs(x)+17.*y.^2).*T./5;
data{T}=z;
end
% [c,h]=contourf(data,100);
% set(h,'linestyle','none')
%%%%%%%動畫
figure(3);
% mesh(x,y,data{1});
view([0 90]);
hold on
% set(h,'linestyle','none')
for i=1:Times
% view([0 90]);
mesh(x,y,data{i});
hold on
% set(h,'linestyle','none')
pause(0.1);
drawnow;
MM(i)
end
hold off
msgbox('完成動畫!!!','完成')
function MM(i)
filename = 'xizh.gif';
f = getframe(gcf);
imind = frame2im(f);
[imind,cm] = rgb2ind(imind,256);
if i==1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf,'DelayTime',0.05);%感覺時間太短改這個,但是儲存就很卡
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.1);%感覺時間太短改這個,但是儲存就很卡
end