文档详情

4、GUI编程实例.doc

发布:2017-08-05约1.1万字共12页下载文档
文本预览下载声明
GUI编程实例 1、以fig方式编写绘制sinx、cosx图像关键程序和操作 首先在gui设计器上放置2个pushbutton、1个popupmenu、2个static text、1个坐标系 function popupmenu_func_Callback(hObject, eventdata, handles) val=get(hObject,value); switch val case 1 handles.data=sin(x); set(handles.text1,string,sin(x)); case 2 handles.data=cos(x); set(handles.text1,string,cos(x)); otherwise handles.data=sin(x); set(handles.text1,string,sin(x)); end guidata(hObject,handles)%最关键 function pushbutton_red_Callback(hObject, eventdata, handles) x=0:0.1:2*pi; if handles.data==sin(x) y=sin(x); plot(x,y,r); end if handles.data==cos(x) y=cos(x); plot(x,y,r); end function pushbutton_blue_Callback(hObject, eventdata, handles) x=0:0.1:2*pi; if handles.data==sin(x) y=sin(x); plot(x,y,b); end if handles.data==cos(x) y=cos(x); plot(x,y,b); end 2、动态增加button figure(MenuBar,none,Name,Gui01,NumberTitle,off,Position,[200,200,100,140]); uicontrol(Style,PushButton,String,Push,Position,[20,100,60,20],... CallBack,disp(You are pressed a push button)); uicontrol(Style,ToggleButton,String,Toggle,Position,[20,60,60,20],... CallBack,disp(You are pressed a toggle button)); uicontrol(Style,PushButton,String,Close,Position,[20,20,60,20],... CallBack,close); 3、函数形式增加button function gui02 figure(MenuBar,none,Name,Gui02,NumberTitle,off,Position,[200,200,100,140]); uicontrol(Style,PushButton,String,Push,Position,[20,100,60,20],... CallBack,@PushButtonPressed); uicontrol(Style,ToggleButton,String,Toggle,Position,[20,60,60,20],... CallBack,@ToggleButtonPressed); uicontrol(Style,PushButton,String,Close,Position,[20,20,60,20],... CallBack,close); function PushButtonPressed(h, eventdata) disp(You are pressed a push button); function ToggleButtonPressed(h, eventdata) disp(You are pressed a toggle button); 4、按钮与静态文本交互操作 function gui03 figure(MenuBar,none,Name,Gui03,NumberTitle,off,Position,[200,200,180,150]); Txt = uicontrol(Style,Text,P
显示全部
相似文档