matlab实验6图形用户界面设计
实验6. 图形用户界面设计
实验目的
掌握图形对象属性的基本操作;
掌握菜单及对话框设计、建立控件对象的方法。
实验环境
计算机
matlab7.x
实验说明
正确操作,认真观察;
实验学时:2学时;
学会使用help;
保存整理实验结果,提交实验报告。
实验内容
1.设计如教材P374 图1所示的菜单,并在此基础上增加选项:可以改变曲线的颜色,可以改变窗口背景颜色。
2.(选做)采用图形用户界面,从键盘输入参数a、b、n的值,考察参数对极坐标曲线的影响。实验程序及结果
1.
figure('Color',[1 1 1],'Position',[400 300 500 250],'Name','201100000',
'NumberTitle','off','MenuBar','none');hplot=uimenu(gcf,'Label','&plot');
%设置Plot菜单项uimenu(hplot,'Label','Sin Wave','Call',['t=-pi:pi/20:pi;','y=sin(t);','plot(t,y);
','set(hgon,''Enable'',''on'');','set(hgoff,''Enable'',''on'');','set(hlinecolor,
''Enable'',''on'');'],'Accelerator','s');
uimenu(hplot,'Label','Cos Wave','Call',['t=-pi:pi/20:pi;','y=cos(t);','plot(t,y);
','set(hgon,''Enable'',''on'');','set(hgoff,''Enable'',''on'');','set(hlinecolor,
''Enable'',''on'');'],'Accelerator','c');
%设置Option菜单项
hoption=uimenu(gcf,'Label','&option');
hgon=uimenu(hoption,'Label','&grid on','Call','grid on','Enable', 'off');
hgoff=uimenu(hoption,'Label','&grid off','Call','grid off','Enable', 'off');
hlinecolor=uimenu(hoption,'Label','&Line Color','Separator','on','Enable', 'off');
uimenu(hlinecolor,'Label','&red','Accelerator','r','Call','set(plot(t,y),''Color'',''r'');');
uimenu(hlinecolor,'Label','&blue','Accelerator','b','Call','set(plot(t,y),''Color'',''b'');');
uimenu(hlinecolor,'Label','&green','Accelerator','g','Call','set(plot(t,y),''Color'',''g'');');
%设置Exit菜单项uimenu(gcf,'Label','Exit','Call','close(gcf)');
%设置快捷菜单hc=uicontextmenu;
hlc=uimenu(hc,'Label','背景颜色');
uimenu(hlc,'Label','red','Call','set(gcf,''Color'',''r'');');
uimenu(hlc,'Label','blue','Call','set(gcf,''Color'',''b'');');
uimenu(hlc,'Label','green','Call','set(gcf,''Color'',''g'');');
set(gcf,'UIContextMenu',hc);
2.
%设置对话框的颜色灰色,大小hf=figure('Color',[0.5 0.5 0.5],'Position',[200 200 400 250],'Name',
'201100000','NumberTitle','off','MenuBar','none');