




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、华东交通大学课程设计报告课 程:MATLAB年 级:2014级 专 业:通信工程班 级:卓越班 学 号:20140610080117 姓 名:江其琪 指导教师:邹丹 第1页 目录第1章 课程设计概要.11.1设计介绍.11.2 基本功能要求1第2章 设计思路与程序22.1 设计思路.22.2 设计功能模块.3 第3章 运行结果及分析93.1运行结果.93.2结果分析.10第4章 心得体会14参考文献12 附录(源程序代码).12第1章 课程设计概要1.1设计介绍本课程设计是利用MATLAB的GUI用户界面所设计的普通计算器。该计算器具有以下功能:1、具有友好的用户图形界面,实现十进制数的加、减
2、、乘、除等简单计算。2、实现部分科学计算函数功能,如求正弦、余弦、平方根等。3、能实现小数运算。4、有清除键,能进行清除操作。1.2基本功能要求利用matlab强大的数值计算功能,便捷的GUI设计功能,实现一个图形用户界面的计算器程序。第 24 页第2章 课题设计内容与步骤2.1设计内容该课程设计的计算器界面如图所示利用MATLAB GUI设计实现一个图形用户界面的计算器程序,可以实现:A. 具有友好的用户图形界面。实现十进制数的加、减、乘、除、乘方、取模等简单计算。B. 科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行。C. 能够保存上次历史计算的答案,
3、先是答案存储器中得内容。D. 有清除键,能清除操作,并对不正确的表达式能指出其错误原因。E.进行二进制数转十进制数及十进制数转二进制数。F.直接退出。2.2设计步骤2.2.1打开GUI界面输入Guide 回车或者在工具栏上点击图标打开Guide 窗口:2.2.2添加按钮2.2.3根据按钮的作用及视觉效果做一定的修改双击按钮(Puch Button)进入按键属性修改显示字符串大小、字体和颜色,然后对按钮的位置进行排布,尽量使按钮集中在静态文本框下面。2.2.4保存、对按钮添加算法各模块算法如下:A.数字键设计:按键“0”:通过get函数获得输入的字符,函数strca
4、t获得字符'0',并用set函数进行显示输出 textString=get(handles.edit1,'String'); if(strcmp(textString,'0')=1) set(handles.edit1,'String','0') else textString=strcat(textString,'0'); set(handles.edit1,'String'
5、,textString) end其他数字按键同上.B.四则运算函数:按键“+”:通过get函数获得输入的字符,函数strcat获得字符'+',并用set函数进行显示输出 textString=get(handles.edit1,'String'); ss=char(textString);l=length(textString); if(ss(l)='+'|ss(l)='-'|ss(l)='*'|ss(l)='/'|ss(l)='.')
6、0; textString=ss(1:l-1); end textString=strcat(textString,'+');set(handles.edit1,'String',textString)按键“-”:通过get函数获得输入的字符,函数strcat获得字符'-',并用set函数进行显示输出 textString=get(handles.edit1,'String');ss=char(textString); l=length(text
7、String); if(ss(l)='+'|ss(l)='-'|ss(l)='*'|ss(l)='/'|ss(l)='.') textString=ss(1:l-1);end textString=strcat(textString,'-'); set(handles.edit1,'String',textString)按键“*”:通过get函数获得输入的字符,函数strcat获得字符'*
8、',并用set函数进行显示输出 textString=get(handles.edit1,'String'); ss=char(textString); l=length(textString); if(ss(l)='+'|ss(l)='-'|ss(l)='*'|ss(l)='/'|ss(l)='.') textString=ss(1:l-1); end textString
9、=strcat(textString,'*'); set(handles.edit1,'String',textString)按键“/”:通过get函数获得输入的字符,函数strcat获得字符'/',并用set函数进行显示输出 textString=get(handles.edit1,'String'); ss=char(textString); l=length(textString); if(ss(l)='+'|ss(l)='-'|ss(l)=&
10、#39;*'|ss(l)='/'|ss(l)='.') textString=ss(1:l-1); end textString=strcat(textString,'/'); set(handles.edit1,'String',textString)按键“.”:通过get函数获得输入的字符,函数strcat获得字符'.',并用set函数进行显示输出 textString=get(handles.edit1,
11、'String'); ss=char(textString); l=length(textString); if(ss(l)='+'|ss(l)='-'|ss(l)='*'|ss(l)='/'|ss(l)='.') textString=ss(1:l-1); end textString=strcat(textString,'.'); set(handles.edit
12、1,'String',textString)按键“+/-”:通过get函数获得输入的字符,函数strcat获得字符'+/-',并用set函数进行显示输出 if(strcmp(textString,'0')=1) set(handles.edit1,'String','0') else a=strread(textString,'%f'); a=0-a; set(handles.edit1,
13、39;String',a) end C.科学计算函数:按键“sin”:通过get函数获得输入的字符,函数strread获得输入字符,并用sin函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); a=strread(textString,'%f'); a=sin(a); set(handles.edit1,'String',a)按键“cos”:通过get函数获得输入的字符,函数strread获得输入字符,并用cos函数计算结果,
14、set函数进行显示输出textString=get(handles.edit1,'String'); a=strread(textString,'%f'); a=cos(a); set(handles.edit1,'String',a)按键“tan”:通过get函数获得输入的字符,函数strread获得输入字符,并用tan函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); if(strcmp(textString,'1.
15、57')=1)|(strcmp(textString,'-1.57')=1) set(handles.edit1,'String','inf'); else a=strread(textString,'%f'); a=tan(a); set(handles.edit1,'String',a) end按键“cot” :通过get函数获得输入的字符,函数strread获得输入字符,并用cot函数计算结果,s
16、et函数进行显示输出textString=get(handles.edit1,'String'); if(strcmp(textString,'3.14')=1)|(strcmp(textString,'0')=1)|(strcmp(textString,'-3.14')=1); set(handles.edit1,'String','inf'); else a=strread(textString,'%f'
17、);a=cot(a); set(handles.edit1,'String',a) end按键“arcsin”:通过get函数获得输入的字符,函数strread获得输入字符,并用arcsin函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); a=strread(textString,'%f'); a=arcsin(a); set(handles.edit1,'String',a)按键“arccos”:通过get函数获得
18、输入的字符,函数strread获得输入字符,并用arccos函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); a=strread(textString,'%f');a=arccos(a); set(handles.edit1,'String',a)按键“arctan”:通过get函数获得输入的字符,函数strread获得输入字符,并用arctan函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String&
19、#39;); a=strread(textString,'%f'); a=arctan(a); set(handles.edit1,'String',a)按键“arccot”:通过get函数获得输入的字符,函数strread获得输入字符,并用arccot函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); a=strread(textString,'%f');a=arccot(a); set(handles.edit1,
20、'String',a)按键“log2”:通过get函数获得输入的字符,函数strread获得输入字符,并用log2函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); if(strcmp(textString,'0')=1) set(handles.edit1,'String','error') else a=strread(textString,'%f');a=
21、log2(a); set(handles.edit1,'String',a) end按键“log10”:通过get函数获得输入的字符,函数strread获得输入字符,并用log10函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','error') else
22、 a=strread(textString,'%f'); a=sin(a); set(handles.edit1,'String',a) end按键“x2”:通过get函数获得输入的字符,函数strread获得输入字符,并用语句a=a*a计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); a=strread(textString,'%f'); a=a*a; set(handles.edit1,'
23、String',a)按键“sqrt”:通过get函数获得输入的字符,函数strread获得输入字符,并用sqrt函数计算结果,set函数进行显示输出textString=get(handles.edit1,'String'); if(strcmp(textString,'0')=1) set(handles.edit1,'String','0') else a=strread(textString,'%f');
24、;a=sqrt(a); set(handles.edit1,'String',a) endD.”DEL”键:通过取屏幕值,计算出其字符长度,然后取其前N-1项的值来实现退格: textString=get(handles.edit1,'String');if(strcmp(textString,'0')=1)&(jj=0) set(handles.edit1,'String','0') else ss
25、=char(textString); l=length(textString); textString=ss(1:l-1); set(handles.edit1,'String',textString)E.清屏“C”键函数:将所有的字符置为'0' set(handles.edit1,'String','0')F.“=”的实现:通过get函数获得输入的字符,并用eval函数计算结果,set函数进行显
26、示输出 a=get(handles.edit1,'string') b=eval(a) set(handles.edit1,'string',num2str(b)第3章 运行结果及分析3.1运行结果A. 数字键:B.四则运算函数:C. 科学计算函数:Sin1的计算结果= 3.2结果分析计算(1+9)/5计算结果=2arcsin1的计算结果log2的报错:通过输入的数据与0字符比较,若两者相等,则显示“error”进行报错,结果如下:经过计算,这些结果均与实际结果相吻合,计算器的功能实现的较为完好。第4
27、章 心得体会本次课程设计用MATLAB的GUI接口设计一个简单的计算器,主要对数字及运算“0-9、+、-、×、÷、.、= 、x2 、sqrt、sin、arcsin、log2”等的代码程序的了解,在设计的过程中也遇到不少的问题,通过和同学的讨论,和老师的交流,让我知道了自己的错误和不足,最终顺利地解决了这些问题。这次课程设计,使我进一步加深了对课本知识的了解和掌握,巩固了所学的基本知识,更加体会到了MATLAB功能的丰富,更加深刻的认识了MATLAB,熟练了编程设计。 其中对计算器按键的颜色、大小和排版,使我的思维更加的缜密,让我在以后的工作生活
28、中,得到了思维的锻炼。在以后学习中,我会更加刻苦,以锻炼自己的能力。参考文献【1】刘卫国.MATLAB程序设计与应用M.北京:高等教育出版 【2】郑阿奇.MATLAB实用教程M.北京:电子工业出版社 【3】罗华飞.MATLAB GUI设计学习手记M.北京:北京航空航天大学出版社 【4】张威.MATLAB基础与编程入门M.西安:西安电子科技大学出版社 【5】孙屹.MATLAB通信仿真开发手册M.北京:国防工业出版社附录function varargout = untitled1(varargin)% UNTITLED1 MATLAB
29、code for untitled1.fig% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing% singleton*.% H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to% the existing singleton*.% UNTITLED1('CALLBACK',hObject,eventData,handles,.) calls the local% function named CALLBAC
30、K in UNTITLED1.M with the given input arguments.% UNTITLED1('Property','Value',.) creates a new UNTITLED1 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before untitled1_OpeningFcn gets called. An% unrecognized property name o
31、r invalid value makes property application% stop. All inputs are passed to untitled1_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 % Edit the above text to modify the re
32、sponse to help untitled1 % Last Modified by GUIDE v2.5 28-Dec-2015 15:21:34 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . 'gui_Singleton', gui_Singleton, . 'gui_OpeningFcn', untitled1_OpeningFcn, . 'gui_OutputFcn
33、9;, untitled1_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization c
34、ode - DO NOT EDIT % - Executes just before untitled1 is made visible.function untitled1_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 w
35、ith handles and user data (see GUIDATA)% varargin command line arguments to untitled1 (see VARARGIN) % Choose default command line output for untitled1handles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes untitled1 wait for user response (see UIRESUME)% uiwait
36、(handles.figure1); % - Outputs from this function are returned to the command line.function varargout = untitled1_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
37、 of MATLAB% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout1 = handles.output; function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version
38、 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 ed
39、it1_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 COMP
40、UTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');end% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to
41、 pushbutton1 (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.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','1') ;elsetextString =
42、strcat(textString,'1');set(handles.edit1,'String',textString)end% - Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles
43、structure with handles and user data (see GUIDATA)textString = get(handles.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','2') ;elsetextString =strcat(textString,'2');set(handles.edit1,'String',textString)end% - Executes on but
44、ton press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (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.edit1,'String');
45、if(strcmp(textString,'0')=1) set(handles.edit1,'String','3') ;elsetextString =strcat(textString,'3');set(handles.edit1,'String',textString)end% - Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle
46、 to pushbutton5 (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.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','4') ;elsetextStrin
47、g =strcat(textString,'4');set(handles.edit1,'String',textString)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 version of MATLAB% handl
48、es structure with handles and user data (see GUIDATA)textString = get(handles.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','5') ;elsetextString =strcat(textString,'5');set(handles.edit1,'String',textString)end% - Executes on
49、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)textString = get(handles.edit1,'String'
50、;);if(strcmp(textString,'0')=1) set(handles.edit1,'String','6') ;elsetextString =strcat(textString,'6');set(handles.edit1,'String',textString)end% - Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject han
51、dle to pushbutton8 (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.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','7') ;elsetextSt
52、ring =strcat(textString,'7');set(handles.edit1,'String',textString)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% ha
53、ndles structure with handles and user data (see GUIDATA)textString = get(handles.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','8') ;elsetextString =strcat(textString,'8');set(handles.edit1,'String',textString)end% - Executes
54、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 GUIDATA)textString = get(handles.edit1,'Stri
55、ng');if(strcmp(textString,'0')=1) set(handles.edit1,'String','9') ;elsetextString =strcat(textString,'9');set(handles.edit1,'String',textString)end % - Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hO
56、bject 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)textString = get(handles.edit1,'String');if(strcmp(textString,'0')=1) set(handles.edit1,'String','0') ;
57、elsetextString =strcat(textString,'0');set(handles.edit1,'String',textString)end% - 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
58、of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.edit1,'String');ss=char(textString);l=length(textString);if(ss(l)='+'|ss(l)='-'|ss(l)='*'|ss(l)='/'|ss(l)='.') textString=ss(1:l-1);endtextString =strcat(text
59、String,'.');set(handles.edit1,'String',textString)% - Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)% hObject handle to pushbutton13 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure w
60、ith handles and user data (see GUIDATA)if(strcmp(textString,'0')=1) set(handles.edit1,'String','0') ;elsea = strread(textString, '%f');a=0-a;set(handles.edit1,'String',a)end% - Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, ev
61、entdata, handles)% hObject handle to pushbutton14 (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.edit1,'String');ss=char(textString);l=length(textString);if(ss(l)='+'|ss(
62、l)='-'|ss(l)='*'|ss(l)='/'|ss(l)='.') textString=ss(1:l-1);endtextString =strcat(textString,'+');set(handles.edit1,'String',textString)% - Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, eventdata, handles)% hObject handle to pushbutton15 (see GCBO)%
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 产地重楼购销合同标准文本
- 秋季学期个人发展计划
- 典当行房产借款合同标准文本
- 农村公寓转让合同标准文本
- 2025装饰装潢工程合同
- 水务行业质量管理体系的构建计划
- 养殖竹鼠合同回收合同标准文本
- 2025年汽车租赁协议合同范文
- 2025建筑设备租赁协议(合同版本)
- 2025专属定制合同及员工手册等企业规章制度服务
- 《小学语文略读课文教学策略》讲座 全国获奖
- 第二章 民事权益保护追求幸福的基石
- 风电场工程可行性研究报告
- 某医学院医学生肾病科疾病教案-肾病综合征
- “水溶液中的多重平衡体系”单元教学设计
- 2023年河南成人学位英语真题及答案
- 《种子学》考试复习题库(附答案)
- 中学生社会实践活动(社区服务)登记表
- 生态保护红线内人类活动生态环境影响评价技术指南
- GB/T 3655-2022用爱泼斯坦方圈测量电工钢带(片)磁性能的方法
- GB/T 34281-2017全民健身活动中心分类配置要求
评论
0/150
提交评论