1、matlab课程设计报告 题 目 简易计算器得设计 学 院 电子信息工程学院 专 业 电子信息 学生姓名与学号 指导教师 一 、选题目得及意义 GUI得广泛应用就是当今计算机发展得重大成就之一,它极大地方便了非专业用户得使用。人们从此不再需要死记硬背大量得命令,取而代之得就是可以通过窗口、菜单、按键等方式来方便地进行操作,而在matlab有很简单得gui设计工具,我们可以通过这个工具轻松地构建我们想要得程序,从而实现与用户得信息交互。本次课程设计就是使用了matlab中得guide生成了简单得计算器程序。 二、源代码 fun
2、ction varargout = Calculator(varargin) %Simple Calculator %Anhui University % Begin initialization code DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', m, 、、、 'gui_Singleton', gui_Singleton, 、、、 'gui_OpeningFcn', Calculator_OpeningFc
3、n, 、、、 'gui_OutputFcn', Calculator_OutputFcn, 、、、 'gui_LayoutFcn', [] , 、、、 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State、gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_m
4、ainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code DO NOT EDIT % Executes just before Calculator is made visible、 function Calculator_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn、
5、 % 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 mand line arguments to Calculator (see VARARGIN) % Choose default mand line output for Calculator handles、output = hObj
6、ect; % Update handles structure guidata(hObject, handles); % UIWAIT makes Calculator wait for user response (see UIRESUME) % uiwait(handles、figure1); % Outputs from this function are returned to the mand line、 function varargout = Calculator_OutputFcn(hObject, eventdata, handles) % varargou
7、t 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 mand line output from handles structure varargout{1} = handles、
8、output; % Executes on button press in p1、 function p1_Callback(hObject, eventdata, handles) % hObject handle to p1 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'str
9、ing'); textstring=strcat(textstring,'1'); set(handles、text1,'string',textstring) % Executes on button press in p2、 function p2_Callback(hObject, eventdata, handles) % hObject handle to p2 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure
10、with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'2'); set(handles、text1,'string',textstring) % Executes on button press in p3、 function p3_Callback(hObject, eventdata, handles) % hObject handle to p3 (see GCBO) % eventdata res
11、erved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'3'); set(handles、text1,'string',textstring) % Executes on button press in p4、 function p4_Callback(hObject,
12、eventdata, handles) % hObject handle to p4 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'4'); set(handles、text1,'string',text
13、string) % Executes on button press in p5、 function p5_Callback(hObject, eventdata, handles) % hObject handle to p5 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'str
14、ing'); textstring=strcat(textstring,'5'); set(handles、text1,'string',textstring) % Executes on button press in p6、 function p6_Callback(hObject, eventdata, handles) % hObject handle to p6 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure
15、with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'6'); set(handles、text1,'string',textstring) % Executes on button press in p7、 function p7_Callback(hObject, eventdata, handles) % hObject handle to p7 (see GCBO) % eventdata res
16、erved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'7'); set(handles、text1,'string',textstring) % Executes on button press in p8、 function p8_Callback(hObject,
17、eventdata, handles) % hObject handle to p8 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'8'); set(handles、text1,'string',text
18、string) % Executes on button press in p9、 function p9_Callback(hObject, eventdata, handles) % hObject handle to p9 (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'str
19、ing'); textstring=strcat(textstring,'9'); set(handles、text1,'string',textstring) % Executes on button press in add、 function add_Callback(hObject, eventdata, handles) % hObject handle to add (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structu
20、re with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'+'); set(handles、text1,'string',textstring) % Executes on button press in p0、 function p0_Callback(hObject, eventdata, handles) % hObject handle to p0 (see GCBO) % eventdata
21、reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'0'); set(handles、text1,'string',textstring) % Executes on button press in sub、 function sub_Callback(hObj
22、ect, eventdata, handles) % hObject handle to sub (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,''); set(handles、text1,'string'
23、textstring) % Executes on button press in div、 function div_Callback(hObject, eventdata, handles) % hObject handle to div (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、te
24、xt1,'string'); textstring=strcat(textstring,'/'); set(handles、text1,'string',textstring) % Executes on button press in mul、 function mul_Callback(hObject, eventdata, handles) % hObject handle to mul (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles
25、 structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'*'); set(handles、text1,'string',textstring) % Executes on button press in denghao、 function denghao_Callback(hObject, eventdata, handles) % hObject handle to denghao (s
26、ee GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=eval(textstring); set(handles、text1,'string',textstring) % Executes on button press in clear、 functio
27、n clear_Callback(hObject, eventdata, handles) % hObject handle to clear (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles、text1,'string','0') % function exit_Callback(hObject, eventdata,
28、 handles) % hObject handle to exit (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(gcf) % function calculate_Callback(hObject, eventdata, handles) % hObject handle to calculate (see GCBO
29、) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=eval(textstring); set(handles、text1,'string',textstring) % Executes on button press in point、 function point
30、Callback(hObject, eventdata, handles) % hObject handle to point (see GCBO) % eventdata reserved to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textstring=get(handles、text1,'string'); textstring=strcat(textstring,'、'); set(handles、text1,'string',textstring) 设计功能: 1. 可进行加减乘除四则运算 2. 可进行清零,退出等 三、界面设计及运行结果 11、 GUIDE 设计界面 12、进入程序初始状态 13、简单得实例测试 五、心得及体会 通过这次matlab课程设计,让我对matlab有了更深得了解。Matlab不仅给我们更方便得编程体验,其中强大得数值运算,信号处理等功能更就是我们专业实现相关系统设计得好工具。
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818