t=0:0.1:2pi;
x=16sin(t).^3;
y=13cos(t)-5cos(2t)-2cos(3t)-cos(4t);
%% 动图画图并保存为GIF
figure;
h = plot(x(1),y(1),‘r’);
axis([-20,20,-20,20]);
text(-2,0,‘爱你’,‘FontSize’,18,‘color’,[1 0 0]);
axis off
[A,map] = rgb2ind(frame2im(getframe),300);%getframe获取当前画面
imwrite(A,map,‘1.gif’,‘LoopCount’,inf,‘DelayTime’,0.1);
for idx = 2:length(t)
h.XData(idx) = x(idx);
h.YData(idx) = y(idx);
drawnow
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,‘1.gif’,‘WriteMode’,‘append’,‘DelayTime’,0.1);
end
f1 = figure;
for j = 1:10
if rem(j,2)== 0
fontsize = 10;
else
fontsize = 30;
end
t1 = text(1,1,‘哈哈,我在这里’,‘FontSize’,fontsize);
pause(1)
delete(t1)
end