clf reset
set(gcf,'unit','normalized','position',[0.1,0.2,0.64,0.35]);
set(gcf,'defaultuicontrolunits','normalized');
set(gcf,'defaultuicontrolfontsize',12);
set(gcf,'defaultuicontrolfontname','隶书');
set(gcf,'defaultuicontrolhorizontal','left');
global Z;
str='李萨如图';
set(gcf,'name',str,'numbertitle','off');
h_axes=axes('position',[0.05,0.2,0.6,0.7]);
set(h_axes,'xlim',[0,15]);
str1='频率比=';
h_text=uicontrol(gcf,'style','text',...
'position',[0.67,0.8,0.33,0.1],...
'string',[str1,sprintf('%1.4g\',Z)]);
h_slider=uicontrol(gcf,'style','slider','position',[0.67,0.65,0.33,0.1],...
'max',6,'min',2,...
'tag','slider',...
'sliderstep',[0.01,0.05],...
'Value',2,...
'callback',[...
'Z=get(gcbo,''value'');',...
'fx=1;',...
'fy=Z*fx;',...
't=linspace(0,1,100);',...
'x=10*sin(2*pi*fx*t)*exp(-1);',...
'y=10*sin(2*pi*fy*t+pi/4)*exp(-1);',...
'plot(x,y);'...
'set(h_text,''string'',[str1,num2str(Z)]);' ]);
给slider 添加一个tag
把 set 移到slider 的'callback'里面就好了 |