正在加载图片...
str=num2str(get(Hc az, 'Value ') newview-Iget( Hc az, ' Value')vw(2)] set(Hc cur,'String set(gca,'View, newview) 上述的两个例子均设置了’tag'属性,利用该属性和函数 findobj寻找回调函数所需对象的句 柄。另外两种方法将在下章描述 全局变量 全局变量可用在函数中,使某些变量对GUI函数的所有部分都可用,全局变量是在函数的 公共区说明,因此整个函数以及所有对函数的递归调用都可以利用全局变量,下面的例子说明 如何利用全局变量将方位角滑标编程 function seaview(switch) global HC AZ HC CUR Create global variables if nargin < 1, switch=startup: end if-isstr(switch, error('Invalid argument ' ):end vw=get(gca, 'View): %This information is needed in both sections if strcmp(switch, '')% Define the controls Hc az=uncontrol(gcf, 'style,'slider Position',[10514020 Min',-90,'Max",90," Value',w(1) Callback,'setview( 'set)): He min=uncontrol(gcf, 'Style,text String, num2str(get(Hc-AZ, 'Min',)) HcMax-uicontrol(gcf, 'Style','text, Position',[10254020], String, num2str(get(Hc AZ,'Max)): He cur=uncontrol(gcf, 'style,text Position',[60254020, String, num2str(get(HC AZ, 'Value)) elseif strcmp(switch, 'set)% Execute the Callback str=num2str(get(HC AZ, Value)); newview=[get(HC AZ, ' Value')vw(2)] set(HC CUR,' String, str)str = num2str(get(Hc_az, ' Value ' )); newview - [get(Hc_az, ' Value ' ) vw(2)]; set(Hc_cur, ' String ' , str) set(gca, ' View ' ,newview) end 上述的两个例子均设置了 ' tag ' 属性,利用该属性和函数findobj寻找回调函数所需对象的句 柄。另外两种方法将在下章描述。 全局变量 全局变量可用在函数中,使某些变量对GUI函数的所有部分都可用,全局变量是在函数的 公共区说明,因此整个函数以及所有对函数的递归调用都可以利用全局变量,下面的例子说明 如何利用全局变量将方位角滑标编程。 function setview(switch) global HC_AZ HC_CUR % Create global variables if nargin < 1, switch = ' startup ' ; end; if ~isstr(switch, error( ' Invalid argument. ' ); end; vw = get (gca, ' View ' ); % This information is needed in both sections if strcmp(switch, ' startup ' ) % Define the controls Hc_AZ=uicontrol(gcf, ' style ' , ' slider ' ,... ' Position ' ,[10 5 140 20],... ' Min ' ,-90, ' Max ' ,90, ' Value ' ,vw(1),... ' Callback ' , ' setview( ' set ' ) ' ); Hc_min=uicontrol(gcf, ' Style ' , ' text ' ,... ' Position ' ,[10 25 40 20],... ' String ' ,num2str(get(Hc-AZ, ' Min ' ,))); HcMax=uicontrol(gcf, ' Style ' , ' text ' ,... ' Position ' ,[110 25 40 20],... ' String ' ,num2str(get(Hc_AZ, ' Max ' ))); Hc_cur=uicontrol(gcf, ' style ' , ' text ' ,... ' Position ' ,[60 25 40 20],... ' String ' ,num2str(get(HC_AZ, ' Value ' ))); elseif strcmp(switch, ' set ' ) % Execute the Callback str=num2str(get(HC_AZ, ' Value ' )); newview= [get(HC_AZ, ' Value ' ) vw(2)]; set(HC_CUR, ' String ' ,str)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有