当前位置:文档之家› 实验8MATLAB图形用户界面设计实验报告

实验8MATLAB图形用户界面设计实验报告

实验8 MATLAB图形用户界面设计实验报告实验报告课程名称:MATLAB应用成绩: 实验项目名称:MATLAB图形用户界面设计实验时间:11.6 指导教师(签名): 班级:XXXXX 姓名:XXXXX 学号:XXX 实验目的:1. 熟悉MATLAB的菜单设计方法2. 熟悉MATLAB的主要控件使用方法3. 熟悉MATLAB的GUI设计流程实验环境:MATLAB 7.1实验内容及过程:简单计算器的设计:在MATLAB GUI的实验环境中,通过MATLAB图形用户界面设计的方法,设计一个简单的计算器,以实现简单数据的退出、清屏、删除、四则运算等基本功能。

实验过程、结果及分析:计算器代码: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(varargin{1})gui_State.gui_Callback = str2func(varargin{1}); endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); elsegui_mainfcn(gui_State, varargin{:});endfunction jsq_OpeningFcn(hObject, eventdata, handles, varargin)guidata(hObject, handles);function varargout = jsq_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles) functionedit1_CreateFcn(hObject, eventdata, handles) if ispc &&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction pushbutton19_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 acase ' 'b='0';case '0'b=a;otherwiseb=a(1:length(a)-1);endset(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) global 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';elsea=strcat(a,'9');%字符串连接endset(handles.edit1,'String',a); guidata(hObject, handles); function pushbutton13_Callback(hObject, eventdata, handles)global a;a=get(handles.edit1,'String'); if a=='0';a='8';elsea=strcat(a,'8');%字符串连接endset(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';elsea=strcat(a,'7');%字符串连接endset(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';elsea=strcat(a,'4');%字符串连接endset(handles.edit1,'String',a); guidata(hObject, handles); 第 3 页共 6 页function pushbutton10_Callback(hObject, eventdata, handles) global a;a=get(handles.edit1,'String'); if a=='0';a='5';elsea=strcat(a,'5');%字符串连接endset(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';elsea=strcat(a,'6');%字符串连接endset(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(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';elsea=strcat(a,'3');%字符串连接endset(handles.edit1,'String',a); guidata(hObject, handles); function pushbutton5_Callback(hObject, eventdata, handles)global a;第 4 页共 6 页a=get(handles.edit1,'String'); if a=='0';a='2';elsea=strcat(a,'2');%字符串连接endset(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';elsea=strcat(a,'1');%字符串连接endset(handles.edit1,'String',a); guidata(hObject, handles); function pushbutton3_Callback(hObject, eventdata, handles)global a;a=get(handles.edit1,'String'); if a=='0';a='0';elsea=strcat(a,'0');%字符串连接endset(handles.edit1,'String',a); guidata(hObject, handles); function pushbutton2_Callback(hObject, eventdata, handles)global a;a=get(handles.edit1,'String'); b=strfind(a,'.');if numel(b)==0a=strcat(a,'.');elseset(handles.edit1,'String',a);endset(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 页。

相关主题