# 0079：Matlab实时动画显示数据图形

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

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

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

https://blog.sciencenet.cn/blog-2777453-1184366.html

## 相关博文

GMT+8, 2024-6-25 07:37