Matlab学习与实验教程-第10章 MATLAB图形用户界面设计_第1页
Matlab学习与实验教程-第10章 MATLAB图形用户界面设计_第2页
Matlab学习与实验教程-第10章 MATLAB图形用户界面设计_第3页
Matlab学习与实验教程-第10章 MATLAB图形用户界面设计_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PAGE29第10章MATLAB图形用户界面设计第10章MATLAB图形用户界面设计例10-1screen=get(0,'ScreenSize');W=screen(3);H=screen(4);figure('Color',[1,1,1],'Position',[0.2*H,0.2*H,0.5*W,0.3*H],...'Name','图形演示系统','NumberTitle','off','MenuBar','none');%定义Plot菜单项hplot=uimenu(gcf,'Label','&Plot');uimenu(hplot,'Label','SineWave','Call',...['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'');']);uimenu(hplot,'Label','CosineWave','Call',...['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'');']);%定义Option菜单项hoption=uimenu(gcf,'Label','&Option');hgon=uimenu(hoption,'Label','&Gridon',...'Call','gridon','Enable','off');hgoff=uimenu(hoption,'Label','&Gridoff',...'Call','gridoff','Enable','off');hbon=uimenu(hoption,'Label','&Boxon',...'separator','on','Call','boxon','Enable','off');hboff=uimenu(hoption,'Label','&Boxoff',...'Call','boxoff','Enable','off');hwincor=uimenu(hoption,'Label','&WindowColor','Separator','on');uimenu(hwincor,'Label','&Red','Accelerator','r',...'Call','set(gcf,''Color'',''r'');');uimenu(hwincor,'Label','&Blue','Accelerator','b',...'Call','set(gcf,''Color'',''b'');');uimenu(hwincor,'Label','&Yellow','Call',...'set(gcf,''Color'',''y'');');uimenu(hwincor,'Label','&White','Call',...'set(gcf,''Color'',''w'');');%定义Quit菜单项uimenu(gcf,'Label','&Quit','Call','close(gcf)');例10-2x=0:pi/100:2*pi;y=2*sin(5*x).*sin(x);hl=plot(x,y);hc=uicontextmenu; %建立快捷菜单hls=uimenu(hc,'Label','线型'); %建立菜单项hlw=uimenu(hc,'Label','线宽');uimenu(hls,'Label','虚线','Call','set(hl,''LineStyle'','':'');');uimenu(hls,'Label','实线','Call','set(hl,''LineStyle'',''-'');');uimenu(hlw,'Label','加宽','Call','set(hl,''LineWidth'',2);');uimenu(hlw,'Label','变细','Call','set(hl,''LineWidth'',0.5);');set(hl,'UIContextMenu',hc); %将该快捷菜单和曲线对象联系起来例10-3hf=figure('Color',[0,1,1],'Position',[100,200,400,200],...'Name','数制转换','NumberTitle','off','MenuBar','none');uicontrol(hf,'Style','Text','Position',[80,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','2~16进制','Back',[1,1,0])he1=uicontrol(hf,'Style','Edit','Position',[100,115,60,25],...'Back',[0,1,0]);he2=uicontrol(hf,'Style','Edit','Position',[100,80,60,25],...'Back',[0,1,0]);uicontrol(hf,'Style','Frame','Position',[215,65,165,90],'Back',[1,1,0])ht=uicontrol(hf,'Style','Text','Position',[255,95,90,30],...'Horizontal','center','Back',[0,1,0]);COMM=['n=str2num(get(he1,''String''));',...'b=str2num(get(he2,''String''));',...'dec=trdec(n,b);','set(ht,''string'',dec);'];uicontrol(hf,'Style','Push','Position',[55,20,90,25],...'String','转换','Call',COMM)uicontrol(hf,'Style','Push','Position',[255,20,90,30],...'String','退出','Call','close(hf)')trdec.m函数文件如下:functiondec=trdec(n,b)ch1='0123456789ABCDEF'; %十六进制的16个符号k=1;whilen~=0 %不断除某进制基数取余直到商为0p(k)=rem(n,b);n=fix(n/b);k=k+1;endk=k-1;strdec='';whilek>=1 %形成某进制数的字符串kb=p(k);strdec=strcat(strdec,ch1(kb+1:kb+1));k=k-1;enddec=strdec;例10-4clf;set(gcf,'Unit','normalized','Position',[0.2,0.3,0.55,0.30]);set(gcf,'Menubar','none','Name','图形演示','NumberTitle','off');axes('Position',[0.05,0.15,0.55,0.7]);uicontrol(gcf,'Style','text','Unit','normalized',...'Posi',[0.63,0.85,0.2,0.1],'String',...'输入绘图命令','Horizontal','center');hedit=uicontrol(gcf,'Style','edit','Unit','normalized',...'Posi',[0.63,0.15,0.2,0.68],...'Max',2);%Max取2,使Max-Min>1,从而允许多行输入hpopup=uicontrol(gcf,'Style','popup','Unit','normalized',...'Posi',[0.85,0.8,0.15,0.15],'String',...'Spring|Summer|Autumn|Winter','Call',...'comm(hedit,hpopup,hlist)');hlist=uicontrol(gcf,'Style','list','Unit','normalized',...'Posi',[0.85,0.55,0.15,0.25],'String',...'Gridon|Gridoff|Boxon|Boxoff','Call',...'comm(hedit,hpopup,hlist)');hpush1=uicontrol(gcf,'Style','push','Unit','normalized',...'Posi',[0.85,0.35,0.15,0.15],'String',...'绘图','Call','comm(hedit,hpopup,hlist)');uicontrol(gcf,'Style','push','Unit','normalized',...'Posi',[0.85,0.15,0.15,0.15],'String',...'关闭','Call','closeall');comm.m函数文件如下:functioncomm(hedit,hpopup,hlist)com=get(hedit,'String');n1=get(hpopup,'Value');n2=get(hlist,'Value');if~isempty(com)%编辑框输入非空时eval(com');%执行从编辑框输入的命令chpop={'spring','summer','autumn','winter'};chlist={'gridon','gridoff','boxon','boxoff'};

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论