当前位置:文档之家› 实验6 图形用户界面设计

实验6 图形用户界面设计

实验6. 图形用户界面设计一、 实验目的1. 掌握图形对象属性的基本操作;2. 掌握菜单及对话框设计、建立控件对象的方法。

二、 实验环境1. 计算机2. matlab7.1三、 实验说明1. 正确操作,认真观察;2. 实验学时:2学时;3. 学会使用help ;4. 保存整理实验结果,提交实验报告。

四、 实验内容1.设计如教材P374 图1所示的菜单,并在此基础上增加选项:可以改变曲线的颜色,可以改变窗口背景颜色。

2.(选做)采用图形用户界面,从键盘输入参数a 、b 、n 的值,考察参数对极坐标曲线)cos(θρn b a +=的影响。

五、 实验程序及结果1. screen=get(0,'ScreenSize');W=screen(3);H=screen(4);figure('Color','w','Position',[0.2*H,0.2*H,0.5*W,0.3*H],...'Name','菜单设计实验','NumberTitle','off','MenuBar','none'); hplot=uimenu(gcf,'Label','&Plot'); %定义plot 菜单项uimenu(hplot,'Label','Sine Wave','Call',...['t=-pi:pi/20:pi;','h0=plot(t,sin(t));',...'set(hlr,''Enable'',''on'');',...'set(hlg,''Enable'',''on'');',...'set(hlb,''Enable'',''on'');']);uimenu(hplot,'Label','Cosine Wave','Call',...['t=-pi:pi/20:pi;','h0=plot(t,cos(t));',...'set(hlr,''Enable'',''on'');',...'set(hlg,''Enable'',''on'');',...'set(hlb,''Enable'',''on'');']);uimenu(hplot,'Label','&Exit','Call','close(gcf)');hc=uimenu(gcf,'Label','&Color'); %定义Color菜单项hw=uimenu(hc,'Label','&Window Color');uimenu(hw,'Label','&Red','Call','set(gcf,''Color'',''r'');');uimenu(hw,'Label','&Green','Call','set(gcf,''Color'',''g'');');uimenu(hw,'Label','&Blue','Call','set(gcf,''Color'',''b'');');hl=uimenu(hc,'Label','&Line Color','Separator','on');hlr=uimenu(hl,'Label','&Red','Call',...'set(h0,''Color'',''r'');','Enable','off');hlg=uimenu(hl,'Label','&Green','Call',...'set(h0,''Color'',''g'');','Enable','off');hlb=uimenu(hl,'Label','&Blue','Call',...'set(h0,''Color'',''b'');','Enable','off');2. hf=figure('menubar','none','name','图形演示',...'numbertitle','off'); %定义图形窗口set(gcf,'unit','normalized','posi',[0.2,0.3,0.55,0.36]);axes('posi',[0.05,0.15,0.55,0.7]); %定义坐标轴uicontrol(gcf,'style','text','unit','normalized',... %定义静态文本'posi',[0.63,0.85,0.1,0.1],'string','参数 a',...'horizontal','center');uicontrol(gcf,'style','text','unit','normalized',...'posi',[0.63,0.65,0.1,0.1],'string','参数 b',...'horizontal','center');uicontrol(gcf,'style','text','unit','normalized',...'posi',[0.63,0.45,0.1,0.1],'string','参数 n',...'horizontal','center');ha=uicontrol(gcf,'style','edit','back','w',... %定义编辑框'unit','normalized', 'posi',[0.80,0.85,0.15,0.1]);hb=uicontrol(gcf,'style','edit','back','w',...'unit','normalized','posi',[0.80,0.65,0.15,0.1]);hn=uicontrol(gcf,'style','edit','back','w',...'unit','normalized','posi',[0.80,0.45,0.15,0.1]);uicontrol(gcf,'style','push','unit','normalized',... %定义按钮'posi',[0.61,0.15,0.15,0.15],'string','绘图','call',COMM); uicontrol(gcf,'style','push','unit','normalized',...'posi',[0.80,0.15,0.15,0.15],'string','关闭','call','close(gcf)');COMM=['a=str2num(get(ha,''string''));',... %绘图'b=str2num(get(hb,''string''));',...'n=str2num(get(hn,''string''));',...'theta=0:0.01:2*pi;',...'rho=a*cos(b+n*theta);',...'polar(theta,rho);'];改变参数a,如图所示改变参数b,如图所示改变参数n,如图所示。

相关主题