matlab GUI函数重复显示

你的hold on都没有hold off,导致了坐标轴不能更新。

函数m要改成如下

function m

global hedit1 hedit2 hpush%定义全局变量

t=linspace(0,2*pi,100);

fill(cos(t),sin(t),'r'); %太阳

hold on;

plot(4*cos(t),sin(t)*4,'k'); %轨迹线

set(gca,'position',[0 0.11 0.7 0.8])

a=0.1;b=0;

xe=4*cos(a)+cos(t)*0.6;

ye=4*sin(a)+sin(t)*0.6;

He=fill(xe,ye,'b'); %地球

set(gcf,'doublebuffer','on'); %启动双缓存

hold off; %这里需要hold off

aa=gca;

axis([-6,6,-6,6]);

axis square;

title('simulate solar system')

%设置右边提示

axes('position',[0.75,0.1,0.25,0.8]);

fill(0.2+cos(t)*0.18,0.75+sin(t)*0.08,'r');

ylim([0,1]);xlim([0,0.9]);

text(0.5,0.75,'Sun');

hold on;

fill(0.2+cos(t)*0.1,0.5+sin(t)*0.05,'b');

text(0.5,0.5,'Earth');

hold off; %这里需要hold off

axis off

axes(aa);%选取图形坐标轴

k=1;da=0.1;db=0.5;

while k;

if strcmp(get(hedit2,'string'),'')

n=0.1;

else

n=str2double(get(hedit2,'string'));

end

a=a+da;

b=b+db;

xe=4*cos(a)+cos(t)*0.6; % 计算地球的横坐标数据

ye=4*sin(a)+sin(t)*0.6; % 计算地球的纵坐标数据

set(He,'xdata',xe,'ydata',ye);%更新地球的数据

pause(n); % 暂停一下显示动画效果

end