|||
源代码:
t=[0]
m=[sin(t);cos(t)];
p = plot(t,m,'EraseMode','background','MarkerSize',5);
x=-1.5*pi;
axis([x x+2*pi -1.5 1.5]);
grid on;
for i=1:1000
t=[t 0.1*i];
wu=[sin(0.1*i);cos(0.1*i)]
m=[m wu];
set(p(1),'XData',t,'YData',m(1,:));
set(p(2),'XData',t,'YData',m(2,:));
drawnow
x=x+0.1;
axis([0 x+2*pi -1.5 1.5]);
pause(0.01);
end
方式2:
clc;
clear;
close all;
t=[0]
m1=[sin(t)];
m2=[cos(t)];
subplot(1,2,1);p1 = plot(t,m1,'EraseMode','background','MarkerSize',5);grid on;
subplot(1,2,2);p2 = plot(t,m2,'EraseMode','background','MarkerSize',5);
x=-1.5*pi;
axis([x x+2*pi -1.5 1.5]);
grid on;
for i=1:1000
t=[t 0.1*i];
m1=[m1 sin(0.1*i)];
m2=[m2 cos(0.1*i)];
set(p1,'XData',t,'YData',m1);
axis([0 x+2*pi -1.5 1.5]);grid on;drawnow
set(p2,'XData',t,'YData',m2);
drawnow
x=x+0.1;
% axis([0 x+2*pi -1.5 1.5]);
end
方式3:
clc;
clear;
close all;
t=[0]
m1=[sin(t)];
m2=[cos(t)];
p1 = plot(t,m1,'EraseMode','background','MarkerSize',5);hold on;
p2 = plot(t,m2,'EraseMode','background','MarkerSize',5);
x=-1.5*pi;
axis([x x+2*pi -1.5 1.5]);
grid on;
for i=1:1000
t=[t 0.1*i];
m1=[m1 sin(0.1*i)];
m2=[m2 cos(0.1*i)];
set(p1,'XData',t,'YData',m1);
drawnow
set(p2,'XData',t,'YData',m2);
drawnow
x=x+0.1;
axis([0 x+2*pi -1.5 1.5]);
pause(0.01);
end
效果图:
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-23 11:57
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社