1、单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,Matlab,图形用户界面设计,8.1,菜单设计,建立用户菜单,调用格式:,一级菜单项句柄,uimenu,(,图形窗口句柄,,属性名,1,,属性值,1,,,),子菜单项句柄,uimenu,(,一级菜单项句柄,,属性名,1,,属性值,1,,,),菜单对象常用属性,Label,:该属性的取值是字符串,用于定义菜单项的名字。,Accelerator,:该属性的取值是任意字母,用于定义菜单项的快捷键。,Callback,:该属性的取值是字符串,可以是某个,M,文件或一组,Matlab,命令。,8.1,菜单设计,菜单
2、对象常用属性,Checked,:,该属性的取值是,on,或,off,,该属性为菜单项定义一个指示标记,可以用这个特性指明菜单项是否已选中。,Enable,:,该属性的取值是,on,或,off,,该属性控制菜单项的可选则性。,Position,:该属性的取值是数值,用于定义一级菜单项在菜单条上的相对位置或子菜单在菜单组内的相对位置。,Separator,:,该属性的取值是,on,或,off,,用于定义菜单项是否加分隔线。,8.1,菜单设计,例,8.1,screen=get(0,ScreenSize,);,W=screen(3);H=screen(4);,figure(Color,1,1,1,Po
3、sition,0.2*H,0.2*H,0.5*W,0.3*H,.,Name,图形演示系统,.,NumberTitle,off,MenuBar,none);,8.1,菜单设计,%,定义,plot,菜单项,hplot,=,uimenu(gcf,Label,uimenu(hplot,Label,Sine,Wave,Callback,.,t=-pi:pi/20:pi;,.,plot(t,sin(t,);,.,set(hgon,Enable,on,);,.,set(hgoff,Enable,on,);,.,set(hbon,Enable,on,);,.,set(hboff,Enable,on,););,
4、uimenu(hplot,Label,Cosine,Wave,Callback,.,t=-pi:pi/20:pi;,.,plot(t,cos(t,);,.,set(hgon,Enable,on,);,.,set(hgoff,Enable,on,);,.,set(hbon,Enable,on,);,.,set(hboff,Enable,on,););,8.1,菜单设计,%,定义,option,菜单项,hoption,=,uimenu(gcf,Label,hgon,=,uimenu(hoption,Label,&Grid,on,Callback,grid,on,Enable,off,);,hgof
5、f,=,uimenu(hoption,Label,&Grid,off,Callback,grid,off,Enable,off,);,hbon,=,uimenu(hoption,Label,&Box,on,Callback,box,on,Enable,off,);,hboff,=,uimenu(hoption,Label,&Box,off,Callback,box,off,Enable,off,);,hwincor,=,uimenu(hoption,Label,&Window,Color,Separator,on,);,uimenu(hwincor,Label,&Red,Accelerator
6、r,Callback,set(gcf,Color,r,););,uimenu(hwincor,Label,&Blue,Accelerator,b,Callback,set(gcf,Color,b,););,uimenu(hwincor,Label,&Yellow,Callback,set(gcf,Color,y,););,uimenu(hwincor,Label,&White,Callback,set(gcf,Color,w,););,8.1,菜单设计,%,定义,quit,菜单项,uimenu(gcf,Label,&Quit,Call,close(gcf,);,8.1,菜单设计,快捷菜单,x
7、pi:pi/100:2*pi;,y=2*exp(-0.5*x).*sin(2*pi*x);,hl=,plot(x,y,);,hc,=,uicontextmenu,;,%,建立快捷菜单,hls,=,uimenu(hc,Label,线型,);,%,建立菜单项,hlw,=,uimenu(hc,Label,线宽,);,uimenu(hls,Label,虚线,Callback,set(hl,LineStyle,:););,uimenu(hls,Label,实线,Callback,set(hl,LineStyle,-););,uimenu(hlw,Label,加宽,Callback,set(hl,Lin
8、eWidth,2););,uimenu(hlw,Label,变细,Callback,set(hl,LineWidth,0.5););,set(hl,UIcontextMenu,hc,);,%,将该快捷菜单和曲线对象联系起来,8.1,菜单设计,8.1,菜单设计,8.2,对话框设计,8.2.1,对话框的控件,按钮(,Push Button,),双位按钮(,Toggle Button,),单选按钮(,Radio Button,),复选框(,Check Box,),列表框(,List Box,),弹出框(,Popup Menu,),编辑框(,Edit Box,),滑动条(,Slider,),静态文本(
9、Static Text,),边框(,Frame,),8.2,对话框设计,8.2,对话框设计,h0=,figure(toolbar,none,.,position,200 150 450 250,.,name,按钮的使用,);,x=0:0.5:2*pi;,y=,sin(x,);,h=,plot(x,y,);,grid on,8.2,对话框设计,test=.,if i=1,.,i=0;,.,y=,cos(x,);,.,delete(h,),.,set(hm,string,正弦函数,),.,h=,plot(x,y,);,.,grid on,.,else if i=0,.,i=1;,.,y=,sin
10、x,);,.,set(hm,string,余弦函数,),.,delete(h,),.,h=,plot(x,y,);,.,grid on,.,end,.,end;,8.2,对话框设计,hm,=,uicontrol(gcf,style,pushbutton,.,string,余弦函数,.,callback,test,);,i=1;,set(hm,position,250 20 60 20);,set(gca,position,0.2 0.2 0.6,0.6,),title(,按钮的使用,),hold on,建立复选框,用于设置图像窗口的某些属性,如大小,颜色,标题等。,htxt,=,uicont
11、rol(gcf,Style,text,Units,normalized,.,Position,.1,.5,.25,.1,String,Set Windows Properties);,hp=,uicontrol(gcf,Style,check,Units,normalized,.,Position,.1,.4,.25,.1,String,MyPosition,.,CallBack,set(gcf,Position,10,10,300,250);,.,if,get(hp,Value,)=1,.,set(gcf,Position,10,10,600,500),end);,hc,=,uicontro
12、l(gcf,Style,check,Units,normalized,.,Position,.1,.3,.25,.1,String,MyColor,.,CallBack,set(gcf,color,w,);,.,if,get(hc,Value,)=1,.,set(gcf,color,w),end,);,hn,=,uicontrol(gcf,Style,check,Units,normalized,.,Position,.1,.2,.25,.1,String,MyName,.,CallBack,set(gcf,Name,复选框未选中,);,.,if,get(hn,Value,)=1,.,set(
13、gcf,Name,复选框被选中,),end);,8.2,对话框设计,图形用户界面设计窗口,方法,File,New,GUI,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,Select,Toggle Button,Push Button,Radio Button,Edit Button,Slider,ListBox,Axis,Check Box,Toggle Button,Static text,Popup Menu,Align Object,Menu Editor,Property
14、Inspector,Object Browser,M-file Editor,例,8.5,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,8.3,可视化图形用户界面设计,function eight_5_OpeningFcn(hObject,eventdata,handles,varargin,),%This function has no output,args,see,OutputFcn,.,%,hObject,handle to figure,%,eventdata,reser
15、ved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),%,varargin,command line arguments to eight_5(see VARARGIN),8.3,可视化图形用户界面设计,handles.peaks,=peaks(35);,handles.membrane,=membrane(5);,x,y,=meshgrid(-8:0.5:8);,r=sqrt(x.2+y.2);,sinc,=,sin(r)./(r+e
16、ps,);,handles.sinc,=,sinc,;,handles.current_data,=,handles.peaks,;,mesh(handles.current_data,);,function popupmenu1_Callback(hObject,eventdata,handles),%,hObject,handle to popupmenu1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user d
17、ata(see GUIDATA),val,=,get(hObject,Value,);,str,=,get(hObject,String,);,switch,strval,case peak,handles.current_data,=,handles.peaks,;,case membrane,handles.current_data,=,handles.membrane,;,case,sinc,handles.current_data,=,handles.sinc,;,end,guidata(hObject,handles,),function pushbutton1_Callback(h
18、Object,eventdata,handles),%,hObject,handle to pushbutton1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),mesh(handles.current_data,);,function,varargout,=test_12_5(varargin),global a b n,function test_12_5_Opening
19、Fcn(hObject,eventdata,handles,varargin,),%This function has no output,args,see,OutputFcn,.,%,hObject,handle to figure,%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),%,varargin,command line arguments to test_12_5(see VARARGI
20、N),global a b n,a=1;b=1;n=1;,theta=-2*pi:0.5:2*pi;,rho,=a*,cos(b+n,*theta);,polar(theta,rho,k,);,function edit1_Callback(hObject,eventdata,handles),%,hObject,handle to edit1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),global a b n,a=str2double(get(hObject,String);,theta=-2*pi:0.5:2*pi;,rho,=a*,cos(b+n,*theta);,polar(theta,rho,b,);,






