您好,欢迎访问三七文档
重庆科技学院数学实验与数学软件课程设计课程名称:菜单与对话框设计开课学期:_2014-2015-1学院:__数理学院开课实验室:_数学实验与建模实验室_学生姓名:谭云文专业班级:应数13-2班__学号:___20134432214_实验十二我们本次实验做的是菜单与对话框设计,所谓菜单与对话框的设计包括在图形用户界面中。而图形用户界面是由窗口、菜单、对话框等各种图形元素组成的用户界面。因为在这种用户界面中,用户的操作既生动形象,又方便灵活,这是它的一大特点。在MATLAB中,基本的图形用户界面对象包含3类:用户界面控件对象、下拉式菜单对象和快捷菜单对象,可以设计出界面友好、操作方便的图形用户界面。其中MATLAB用户菜单对象是图形窗口的子对象,所以菜单设计总在某一个图形窗口中进行。MATLAB的图形窗口有自己的菜单栏。为了建立用户自己的菜单系统,可以先将图形窗口的MenuBar属性设置为none,以取消图形窗口默认的菜单,然后再建立用户自己的菜单。对话框是用户与计算机进行信息交流的临时窗口,在现代软件中有着广泛的应用。在软件设计时,借助于对话框可以更好地满足用户操作需要,使用户操作更加方面灵活。为了更便捷地进行用户界面设计,MATLAB提供了图形用户界面开发环境,这使得界面设计在可视化状态进行,设计过程中变得简单直观,实现了“所见即所得”。例1一、实验目的1.掌握plot菜单的方法。2.掌握建立控件对象的方法。3.掌握对话框设计的方法。二、实验内容设计图1所示的菜单。菜单条上仅有Plot菜单,其中有SineWave、CosineWave和Exit共3个命令。若选择了其中的SineWave命令,则将绘制出正弦曲线;若选择了其中的CosineWave命令,则将绘制出余弦曲线;如果选择了Exit命令,则将关闭窗口。程序如下: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');%plothplot=uimenu(gcf,'Label','&Plot');uimenu(hplot,'Label','SineWave','Call',...['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));',...'set(hgon,''Enable'',''on'');',...'set(hgoff,''Enable'',''on'');',...'set(hbon,''Enable'',''on'');',...'set(hboff,''Enable'',''on'');']);uimenu(hplot,'Label','&Exit','Call','close(gcf)');三、运行结果1.点击SineWave函数将出现我们所需要的图像,如图:2点击CosineWave函数将出现我们所需要的图像,如图:3.点击Exit命令,这个窗口将会关闭。例5一、实验目的1.掌握图形用户界面(GUI)设计的模板和窗口。2.掌握GUI可视化设计工具。二、实验内容采用图形用户界面,从键盘输入参数a、b、n的值,考察参数对极坐标曲线rho=a*cos(b+n*theta)的影响。三、运行步骤1.打开MATLAB,选择File命令下的New,建立GUI界面,如下图:2.建立GUI界面,然后添加相应按钮:,分别更改其代码为a,b,n。则出现:,删除其代码,则为:不做处理,绘制其画图区域大小:添加绘图按钮:,更改代码为:绘制图像。处理好后完整如下图:3.在此窗口中的View中选择M-fileEditor,即出现相应的程序代码:4.然后添加极坐标曲线pho=acos(b+n*theta)程序(代码),如下:functionvarargout=untitled5(varargin)%UNTITLED5M-fileforuntitled5.fig%UNTITLED5,byitself,createsanewUNTITLED5orraisestheexisting%singleton*.%%H=UNTITLED5returnsthehandletoanewUNTITLED5orthehandleto%theexistingsingleton*.%%UNTITLED5('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinUNTITLED5.Mwiththegiveninputarguments.%%UNTITLED5('Property','Value',...)createsanewUNTITLED5orraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforeuntitled5_OpeningFunctiongetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.Allinputsarepassedtountitled5_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.ChooseGUIallowsonlyone%instancetorun(singleton).%%Seealso:GUIDE,GUIDATA,GUIHANDLES%Copyright2002-2003TheMathWorks,Inc.%Edittheabovetexttomodifytheresponsetohelpuntitled5%LastModifiedbyGUIDEv2.508-Jan-201516:30:47%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@untitled5_OpeningFcn,...'gui_OutputFcn',@untitled5_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endifnargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});elsegui_mainfcn(gui_State,varargin{:});end%Endinitializationcode-DONOTEDIT%---Executesjustbeforeuntitled5ismadevisible.functionuntitled5_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstountitled5(seeVARARGIN)%Choosedefaultcommandlineoutputforuntitled5handles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesuntitled5waitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%---Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=untitled5_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;functionedit1_Callback(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofedit1astext%str2double(get(hObject,'String'))returnscontentsofedit1asadouble%---Executesduringobjectcreation,aftersettingallproperties.functionedit1_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunctionedit2_Callback(hObject,eventdata,handles)%hObjecthandletoedit2(seeGCBO)%eventdatareserve
本文标题:数学实验软件
链接地址:https://www.777doc.com/doc-2331262 .html