资源描述:
《第08章_matlab图形用户界面设计_例题源程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、高教社刘卫国《MATLAB程序设计与应用》(第二版)例题源程序第8章:MATLAB图形用户界面设计第8章MATLAB图形用户界面设计例8.1建立图8.1所示的图形演示系统菜单。菜单条中含有3个菜单项:Plot、Option和Quit。Plot中有SineWave和CosineWave两个子菜单项,分别控制在本图形窗口画出正弦和余弦曲线。Option菜单项的内容如图8.1所示,其中Gridon和Gridoff控制给坐标轴加网格线,Boxon和Boxoff控制给坐标轴加边框,而且这4项只有在画有曲线时才是可选的。WindowColor控制
2、图形窗口背景颜色。Quit控制是否退出系统。screen=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','Cal
3、l',...['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));',...'se
4、t(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(
5、hoption,'Label','&Gridoff',...'Call','gridoff','Enable','off');hbon=uimenu(hoption,'Label','&Boxon',...8王成优©山东大学(威海)MATLAB语言WangChengyou©ShandongUniversity,Weihai高教社刘卫国《MATLAB程序设计与应用》(第二版)例题源程序第8章:MATLAB图形用户界面设计'separator','on','Call','boxon','Enable','off');hboff=uimen
6、u(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',...'Cal
7、l','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),并建立一个与之相联系的
8、快捷菜单,用以控制曲线的线型和曲线宽度。x=0:pi/100:2*pi;y=2*exp(-0.5*x).*sin(2*pi*x);hl=plot(x,y);hc=uicontextmenu;%建立快捷菜单hls=uime