实验6
实验6. 图形用户界面设计
一、 实验目的
1. 掌握图形对象属性的基本操作;
2. 掌握菜单及对话框设计、建立控件对象的方法。 二、 实验环境
1. 计算机 2. matlab7.1 三、 实验说明
1. 正确操作,认真观察; 2. 实验学时:2学时; 3. 学会使用help;
4. 保存整理实验结果,提交实验报告。 四、 实验内容
1.设计如教材P374 图1所示的菜单,并在此基础上增加选项:可以改变曲线的颜色,可以改变窗口背景颜色。
2.(选做)采用图形用户界面,从键盘输入参数a、b、n的值,考察参数对极坐标曲线??acos(b?n?)的影响。五、 实验程序及结果
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));',...
1
实验6
'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',...
2
实验6
'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,如图所示
3
实验6
改变参数b,如图所示
改变参数n,如图所示
4
实验6
5
相关推荐: