重庆科技学院数学实验与数学软件课程设计课程名称:菜单与对话框设计开课学期:_2014-2015-1学院:__ 数理学院开课实验室:_数学实验与建模实验室_学生姓名: 谭云文专业班级: 应数13-2班 __学号:___ 20134432214 _实验十二我们本次实验做的是菜单与对话框设计,所谓菜单与对话框的设计包括在图形用户界面中。
而图形用户界面是由窗口、菜单、对话框等各种图形元素组成的用户界面。
因为在这种用户界面中,用户的操作既生动形象,又方便灵活,这是它的一大特点。
在MATLAB中,基本的图形用户界面对象包含3类:用户界面控件对象、下拉式菜单对象和快捷菜单对象,可以设计出界面友好、操作方便的图形用户界面。
其中MATLAB用户菜单对象是图形窗口的子对象,所以菜单设计总在某一个图形窗口中进行。
MATLAB的图形窗口有自己的菜单栏。
为了建立用户自己的菜单系统,可以先将图形窗口的MenuBar属性设置为none,以取消图形窗口默认的菜单,然后再建立用户自己的菜单。
对话框是用户与计算机进行信息交流的临时窗口,在现代软件中有着广泛的应用。
在软件设计时,借助于对话框可以更好地满足用户操作需要,使用户操作更加方面灵活。
为了更便捷地进行用户界面设计,MATLAB提供了图形用户界面开发环境,这使得界面设计在可视化状态进行,设计过程中变得简单直观,实现了“所见即所得”。
例1一、实验目的1. 掌握plot菜单的方法。
2. 掌握建立控件对象的方法。
3. 掌握对话框设计的方法。
二、实验内容设计图1所示的菜单。
菜单条上仅有Plot菜单,其中有Sine Wave、Cosine Wave和Exit共3个命令。
若选择了其中的Sine Wave命令,则将绘制出正弦曲线;若选择了其中的Cosine Wave命令,则将绘制出余弦曲线;如果选择了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','Sine Wave','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','Cosine Wave','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-file Editor,即出现相应的程序代码:4.然后添加极坐标曲线pho=acos(b+n*theta)程序(代码),如下:function varargout = untitled5(varargin)% UNTITLED5 M-file for untitled5.fig% UNTITLED5, by itself, creates a new UNTITLED5 or raises the existing% singleton*.%% H = UNTITLED5 returns the handle to a new UNTITLED5 or the handle to% the existing singleton*.%% UNTITLED5('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in UNTITLED5.M with the given input arguments.%% UNTITLED5('Property','Value',...) creates a new UNTITLED5 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before untitled5_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to untitled5_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Copyright 2002-2003 The MathWorks, Inc.% Edit the above text to modify the response to help untitled5% Last Modified by GUIDE v2.5 08-Jan-2015 16:30:47% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @untitled5_OpeningFcn, ...'gui_OutputFcn', @untitled5_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before untitled5 is made visible.function untitled5_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to untitled5 (see VARARGIN)% Choose default command line output for untitled5handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes untitled5 wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = untitled5_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor' ));endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor' ));endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 asa double% --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor' ));end% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)a=get(handles.edit1,'string')b=get(handles.edit2,'string')n=get(handles.edit3,'string')theta=0:0.01:2*pi;rho=a*cos(b+n*theta);polar(theta,rho,'r')四、运行结果运行其程序,则出现:输入相应的值,则出现对应图像:若输入a=10,b=0.1,n=10,则若输入a=0.1,b=10,n=10,则。