方法一
clc;clear
h = animatedline('Color','r','LineWidth',3);
h2 = animatedline('Color','g','LineWidth',3);
h3 = animatedline('Color','b','LineWidth',3);
set(gca,'XTick',[0,0.005,0.01,0.015,0.02]);
axis([0,0.02,-1,1]);
xlabel('Time (s)');
ylabel('Three-Phase Currents (A)');
w=2*pi*50;
t = linspace(0,0.02,100);
ia = sin(w*t);
ib = sin(w*t-2*pi/3);
ic = sin(w*t+2*pi/3);
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,'ThreePhaseCurrent.gif','LoopCount',65535,'DelayTime',0);
for k = 1:length(t)
addpoints(h,t(k),ia(k));
addpoints(h2,t(k),ib(k));
addpoints(h3,t(k),ic(k));
drawnow
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,'ThreePhaseCurrent.gif','WriteMode','append','DelayTime',0);
end
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/ecc43252ca689cc2afad3f40b7fdbc55.gif)
方法二
clc;clear;close all;
pic_num = 1;
dx = 0.2;
x = - 2 * pi : dx : 2 * pi;
y1 = sin(x);
y2 = sin(x -2/3*pi);
y3 = sin(x +2/3*pi);
y4 = y1+y2+y3;
for i = 1 : length(x) / 2+1
plot(x + i * dx, y1, 'b',...
x + i * dx, y2, 'g',...
x + i * dx, y3, 'r',...
x + i * dx, y4, 'k');
box off;
axis([0 2*pi -1 1]);
%-----------------------No need modify-----------------------------------------------
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_num == 1
imwrite(I,map,'test2.gif','gif','Loopcount',inf,'DelayTime',0.2);
else
imwrite(I,map,'test2.gif','gif','WriteMode','append','DelayTime',0.2);
end
pic_num = pic_num + 1;
%----------------------------------------------------------------------
end
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/a43a2de7d39926a0efb14ef0e4f913ca.gif)