《实验8MATLAB图形用户界面设计实验报告.docx》由会员分享,可在线阅读,更多相关《实验8MATLAB图形用户界面设计实验报告.docx(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、实验8MATLAB图形用户界面设计实验报告 实验8 MATLAB图形用户界面设计实验报告实验报告 课程名称:MATLAB应用成绩: 实验项目名称:MATLAB图形用户界面设计实验时间:11.6 指导教师(签名): 班级:XXXXX 姓名:XXXXX 学号:XXX 实验目的: 1. 熟悉MATLAB的菜单设计方法 2. 熟悉MATLAB的主要控件使用方法 3. 熟悉MATLAB的GUI设计流程 实验环境: MATLAB 7.1 实验内容及过程: 简单计算器的设计:在MATLAB GUI的实验环境中,通过MATLAB图形用户界面设计的方法,设计一个 简单的计算器,以实现简单数据的退出、清屏、删除、
2、四则运算等基本功能。 实验过程、结果及分析: 计算器代码: function varargout = jsq(varargin) gui_Singleton = 1; gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . 第 1 页共 6 页 gui_OpeningFcn, jsq_OpeningFcn, . gui_OutputFcn, jsq_OutputFcn, . gui_LayoutFcn, , . gui_Callback, ); if nargin & ischar(varargin1)
3、 gui_State.gui_Callback = str2func(varargin1); end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:); else gui_mainfcn(gui_State, varargin:); end function jsq_OpeningFcn(hObject, eventdata, handles, varargin) guidata(hObject, handles); function varargout = jsq_OutputFcn(hObject, even
4、tdata, handles) varargout1 = handles.output; function edit1_Callback(hObject, eventdata, handles) function edit1_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function pushbutton19
5、_Callback(hObject, eventdata, handles) close(gcf); function pushbutton17_Callback(hObject, eventdata, handles) set(handles.edit1,String,0); function pushbutton18_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); switch a case b=0; case 0 b=a; otherwise b=a(1:length(a)-1);
6、end set(handles.edit1,String,b); guidata(hObject, handles); % - Executes on button press in pushbutton4. function pushbutton16_Callback(hObject, eventdata, handles) global a; global b; b=strcat(b,strcat(a,+); set(handles.edit1,String,0); function pushbutton15_Callback(hObject, eventdata, handles) gl
7、obal a; 第 2 页共 6 页 global b; b=strcat(b,strcat(a,-); set(handles.edit1,String,0); function pushbutton14_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=9; else a=strcat(a,9);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton1
8、3_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=8; else a=strcat(a,8);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton12_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=7; else a=str
9、cat(a,7);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton11_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=4; else a=strcat(a,4);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); 第 3 页共 6 页 function pushbu
10、tton10_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=5; else a=strcat(a,5);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton9_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=6; else a
11、=strcat(a,6);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton8_Callback(hObject, eventdata, handles) global a; global b; b=strcat(b,strcat(a,*); set(handles.edit1,String,0); function pushbutton7_Callback(hObject, eventdata, handles) global a; global b; b=strcat(
12、b,strcat(a,/); set(handles.edit1,String,0); function pushbutton6_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=3; else a=strcat(a,3);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton5_Callback(hObject, eventdata, handles)
13、global a; 第 4 页共 6 页 a=get(handles.edit1,String); if a=0; a=2; else a=strcat(a,2);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton4_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=1; else a=strcat(a,1);%字符串连接 end set(handle
14、s.edit1,String,a); guidata(hObject, handles); function pushbutton3_Callback(hObject, eventdata, handles) global a; a=get(handles.edit1,String); if a=0; a=0; else a=strcat(a,0);%字符串连接 end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton2_Callback(hObject, eventdata, handles
15、) global a; a=get(handles.edit1,String); b=strfind(a,.); if numel(b)=0 a=strcat(a,.); else set(handles.edit1,String,a); end set(handles.edit1,String,a); guidata(hObject, handles); function pushbutton1_Callback(hObject, eventdata, handles) global a; global b; c=get(handles.edit1,String); d=strcat(b,c); a=eval(d); b=0; %避免出现累加问题 第 5 页共 6 页 set(handles.edit1,String,a); a=num2str(a); guidata(hObject, handles); 第 6 页共 6 页