1、GUI设计的简易计算器附程序电子信息工程系实验报告成 绩:课程名称:MATLAB应用 指导教师(签名):实验项目名称:GUI计算器设计 实验时间:2012-11-22 班级:测控081 姓名: 学号:810707132 实 验 目 的: 1.熟悉MATLAB的菜单设计方法2. 熟悉MATLAB的主要控件使用方法3. 熟悉MATLAB的GUI设计流程4.运用MATLAB的GUI设计一个简单的计算器实 验 环 境: MATLAB7.8实 验 内 容:function varargout = jisuanqi1(varargin)% JISUANQI1 M-file for jisuanqi1.fi
2、g% JISUANQI1, by itself, creates a new JISUANQI1 or raises the existing% singleton*.% H = JISUANQI1 returns the handle to a new JISUANQI1 or the handle to% the existing singleton*.% JISUANQI1(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in JISUANQI1.M with the given
3、 input arguments.% JISUANQI1(Property,Value,.) creates a new JISUANQI1 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before jisuanqi1_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% st
4、op. All inputs are passed to jisuanqi1_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help jisuanqi1 % Last Modified by GUIDE v2.5 05-Dec-2
5、010 22:24:59 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, jisuanqi1_OpeningFcn, . gui_OutputFcn, jisuanqi1_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.g
6、ui_Callback = str2func(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT % - Executes just before jisuanqi1 is made visible.function jisuanqi1_OpeningFcn(hObject, eventdata, handles, vara
7、rgin)% 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 jisuanqi1 (see VARARGIN)% 以下是本实验初始化部分程序的代码:global c p t
8、c1 f;f=0;t=0;p=2;c1=num2str(0);c= 0.;set(handles.edit1,String,c);guidata(hObject, handles);% Choose default command line output for jisuanqi1handles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes jisuanqi1 wait for user response (see UIRESUME)% uiwait(handles.f
9、igure1); % - Outputs from this function are returned to the command line.function varargout = jisuanqi1_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
10、% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout1 = handles.output; % - Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdat
11、a reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验数字8的程序代码:global t f c;if f=; c=0; c=8+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);elseif t=0; c=8+str2num(c)*10; c= num2str(c); set(han
12、dles.edit1,String,c); guidata(hObject, handles);else c=strcat(c,8); set(handles.edit1,String,c); guidata(hObject, handles); t=t+1;end% - Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved -
13、to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验数字5的程序代码:global t f c;if f=; c=0; c=5+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);elseif t=0; c=5+str2num(c)*10; c= num2str(c); set(handles.edit1,St
14、ring,c); guidata(hObject, handles);else c=strcat(c,5); set(handles.edit1,String,c); guidata(hObject, handles); t=t+1;end% - Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined
15、 in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验数字2的程序代码:global t f c;if f=; c=0; c=2+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);elseif t=0; c=2+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guid
16、ata(hObject, handles);else c=strcat(c,2); set(handles.edit1,String,c); guidata(hObject, handles); t=t+1;end % - Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future
17、 version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验+/-的程序代码:global c t p;if rem(p,2)=0; c=strcat(-,c); set(handles.edit1,String,c); guidata(hObject, handles); p=p+1;else c=strrep(c,-,); set(handles.edit1,String,c); guidata(hObject, handles); p=p+1;end% - Executes o
18、n button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验.的程序代码:global c t;t=1;c=strcat(c,.);
19、set(handles.edit1,String,c);guidata(hObject, handles); % - Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles an
20、d user data (see GUIDATA)% 以下是本实验数字3的程序代码:global t f c;if f=; c=0; c=3+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);elseif t=0; c=3+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);else c=strcat(c,3); set(handles.edit1,Strin
21、g,c); guidata(hObject, handles); t=t+1;end% - Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject handle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (
22、see GUIDATA)% 以下是本实验数字6的程序代码:global t f c;if f=; c=0; c=6+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);elseif t=0; c=6+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);else c=strcat(c,6); set(handles.edit1,String,c); guidata
23、(hObject, handles); t=t+1;end% - Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDAT
24、A)% 以下是本实验数字9的程序代码:global t f c;if f=; c=0; c=9+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);elseif t=0; c=9+str2num(c)*10; c= num2str(c); set(handles.edit1,String,c); guidata(hObject, handles);else c=strcat(c,9); set(handles.edit1,String,c); guidata(hObject,
25、handles); t=t+1;end% - Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject handle to pushbutton11 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验
26、+的程序代码:global c c1 f t;if f=-; c1=str2num(c1)-str2num(c); c1=num2str(c1); set(handles.edit1,String,c1); guidata(hObject, handles); c=num2str(0); f=+; elseif f=/&str2num(c)=0; c2= set(handles.edit1,String,c2); guidata(hObject, handles); c=num2str(0); c1=num2str(0); f=; elseif f=/; c1=str2num(c1)/str2
27、num(c); c1=num2str(c1); set(handles.edit1,String,c1); guidata(hObject, handles); c=num2str(0); f=+; elseif f=*; c1=str2num(c)*str2num(c1); c1=num2str(c1); set(handles.edit1,String,c1); guidata(hObject, handles); c=num2str(0); f=+;else c1=str2num(c)+str2num(c1); c1=num2str(c1); set(handles.edit1,Stri
28、ng,c1); guidata(hObject, handles); c=num2str(0); f=+;endt=0;% - Executes on button press in pushbutton12.function pushbutton12_Callback(hObject, eventdata, handles)% hObject handle to pushbutton12 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with ha
29、ndles and user data (see GUIDATA)% 以下是本实验-的程序代码:global c c1 f t;if (c1=num2str(0)&f=0)|(c1=num2str(0)&f=) c1=str2num(c)-str2num(c1); c1=num2str(c1); set(handles.edit1,String,c1); guidata(hObject, handles); c=num2str(0); f=-; elseif f=+; c1=str2num(c)+str2num(c1); c1=num2str(c1); set(handles.edit1,String,c1); guidata(hObject, handles); c=num2str(0); f=-; elseif f=/&str2num(c)=0; c2= set(handles.edit1,String,c2); guidata(hObject, handles); c=num2str(0); c1=num2str(0); f=;elseif f=/; c1=str2num(c1)/str2num(c); c1=num2str(c1); set(handles.edit1,String,c1); guidata(hObject, h
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1