《刘卫国全套配套课件matlab程序设计与应用第3版第11章matlab图形用户界面设计源程序》由会员分享,可在线阅读,更多相关《刘卫国全套配套课件matlab程序设计与应用第3版第11章matlab图形用户界面设计源程序(9页珍藏版)》请在金锄头文库上搜索。
1、第11章 MATLAB图形用户界面设计3建立控件对象举例(1)建立按钮和双位按钮程序如下:pbstart=uicontrol(gcf,Style,push,Position,. 50,5,60,25,String,Start Plot,. CallBack,t=-pi:pi/20:pi;plot(t,sin(t);ptgrid=uicontrol(gcf,Style,toggle,Position,. 150,5,60,25,String,Grid,CallBack,grid);(2)建立单选按钮程序如下:set(gcf,Color,R) %设置默认的背景颜色htxt=uicontrol(gc
2、f,Style,text,String,. Color Options,Position,200,130,150,20);%建立单选按钮hr=uicontrol(gcf,Style,radio,String,. Red,Position,200,100,150,25,Value,1,. CallBack,set(hr,Value,1);,set(hb,Value,0);,. set(hy,Value,0);,set(gcf,Color,R);hb=uicontrol(gcf,Style,radio,String,. Blue,Position,200,75,150,25,. CallBack,
3、set(hb,Value,1),set(hr,Value,0);,. set(hy,Value,0);,set(gcf,Color,B);hy=uicontrol(gcf,Style,radio,String,. Yellow,Position,200,50,150,25,. CallBack,set(hy,Value,1),set(hr,Value,0);,. set(hb,Value,0);,set(gcf,Color,Y);(3)建立复选框程序如下:htxt=uicontrol(gcf,Style,text,Position,200,125,150,25,. String,Set Win
4、dows Properties);hp=uicontrol(gcf,Style,check,Position,. 200,100,150,25,String,MyPosition,. CallBack,set(gcf,Position,10,10,300,250);,. if get(hp,Value)=1,. set(gcf,Position,10,10,600,500),end);hc=uicontrol(gcf,Style,check,Position,. 200,75,150,25,String,MyColor,. CallBack,set(gcf,color,w);,. if get
5、(hc,Value) =1,set(gcf,color,g),end);hn=uicontrol(gcf,Style,check,Position,. 200,50,150,25,String,MyName,. CallBack,set(gcf,Name,复选框未选中);,. if get(hn,Value) =1,. set(gcf,Name,复选框被选中),end);(4)建立弹出框程序如下:hpop=uicontrol(gcf,Style,popup,String,. red|blue|green|yellow|white,Position,100,100,100,80,. CallBa
6、ck,cbcol=R,B,G,Y;,. set(gcf,Color,cbcol(get(hpop,Value);(5)建立列表框界面中列表框的作用与(4)同,程序如下:hl=uicontrol(gcf,Style,list,. String,red|blue|green|yellow|white,. Position,100,100,100,80,CallBack,. cbcol=r,b,g,y,w,k;,. set(gcf,color,cbcol(get(hl,value););(6)建立编辑框及边框程序如下:ftdir=uicontrol(gcf,Style,frame,. back,y,
7、Position,30,180,120,100);edmulti=uicontrol(gcf,Style,edit,. String,MATLAB is a very useful language.,. Position,50,200,75,55,Max,2,back,w);(7)建立滑动条程序如下:fig=figure(Position,20,20,400,150);hsli1=uicontrol(fig,Style,slider,Position,. 50,50,120,20,Min,200,Max,800,Value,400,. CallBack,set(azmcur,String,.
8、 num2str(get(hsli1,Value);. set(gcf,Position,20,20,get(hsli1,Value),300););hsli2=uicontrol(fig,Style,slider,Position,. 240,50,120,20,Min,100,Max,600,Value,300,. CallBack,set(elvcur,String,. num2str(get(hsli2,Value);,. set(gcf,Position,20,20,400,get(hsli2,Value););%用静态文本标出最小值azmmin=uicontrol(fig,Styl
9、e,text,Position,. 20,50,30,20,String,num2str(get(hsli1,Min);elvmin=uicontrol(fig,Style,text,Position,. 210,50,30,20,String,num2str(get(hsli2,Min);%用静态文本标出最大值azmmax=uicontrol(fig,Style,text,Position,. 170,50,30,20,String,num2str(get(hsli1,Max);elvmax=uicontrol(fig,Style,text,Position,. 360,50,30,20,S
10、tring,num2str(get(hsli2,Max);%用静态文本标出当前设置的宽度和高度azmLabel=uicontrol(fig,Style,text,Position,. 50,80,65,20,String,Width);elvLabel=uicontrol(fig,Style,text,Position,. 240,80,65,20,String,Height);azmcur=uicontrol(fig,Style,text,Position,. 120,80,50,20,String,num2str(get(hsli1,Value);elvcur=uicontrol(fig,
11、Style,text,Position,. 310,80,50,20,String,num2str(get(hsli2,Value);例11-1 建立如图11-8所示的数制转换对话框,在左边输入一个十进制整数和216之间的数,单击“转换”按钮能在右边得到十进制数所对应的216进制字符串,单击“退出”按钮退出对话框。图11-8 数制转换对话框程序如下:hf=figure(Color,0,1,1,Position,100,200,400,200,. Name,数制转换,NumberTitle,off,MenuBar,none);uicontrol(hf,Style,Text,Position,80
12、,160,40,20,. Horizontal,center,String,输入框,Back,0,1,1)uicontrol(hf,Style,Text,Position,280,160,40,20,. Horizontal,center,String,输出框,Back,0,1,1)uicontrol(hf,Style,Frame,Position,20,65,165,90,Back,1,1,0)uicontrol(hf,Style,Text,Position,25,110,85,25,. Horizontal,center,String,十进制数,Back,1,1,0)uicontrol(hf,Style,Text,Position,25,75,85,25,. Horizontal,center,String,216进制,Back,1,1,0)he1=u