资源描述:
《第08章_MATLAB图形用户界面设计_例题源程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第8章MATLAB图形用户界面设计例8.1建立图8.1所示的图形演示系统菜单。菜单条中含有3个菜单项:Plot、Option和Quit。Plot中有SineWave和CosineWave两个子菜单项,分别控制在本图形窗口画出正弦和余弦曲线。Option菜单项的内容如图8.1所示,其中Gridon和Gridoff控制给坐标轴加网格线,Boxon和Boxoff控制给坐标轴加边框,而且这4项只有在画有曲线时才是可选的。WindowColor控制图形窗口背景颜色。Quit控制是否退出系统。screen=get(0,'ScreenSize');W=screen(3);H=scr
2、een(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'');',...'se
3、t(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'');',...
4、'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','o
5、n','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','&Blu
6、e','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)');例8.2绘制曲线y=2e-0.5xsin(2πx),
7、并建立一个与之相联系的快捷菜单,用以控制曲线的线型和曲线宽度。x=0:pi/100:2*pi;y=2*exp(-0.5*x).*sin(2*pi*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,'