




已阅读5页,还剩37页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
三 江 学 院专 科 毕 业 设 计题 目 简易计算器的设计及应用 三江学院高职院 院(系) 电子信息工程技术 专业学 号 学生姓名 指导教师 起讫日期 2010年12月6日2011年3月11日 设计地点 三江学院高职院 目 录目 录II摘 要IIISummaryIV1设计目的- 1 -2题目分析- 1 -2.1课程设计的基本要求:- 1 -2.2课程设计的内容- 1 -2.3题目分析- 1 -3总体设计- 2 -4具体设计- 2 -4.1各功能界面设计- 2 -4.2各功能模块实现- 3 -4.3各模块实现结果- 5 -5结果分析- 7 -5.1测试结果:- 7 -5.2问题和解决方法:- 10 -6心得体会- 10 -7附录(源代码)- 11 -8总 结- 36 -9参 考 文 献- 36 -摘 要 matlab是一种用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境。使用 MATLAB,您可以较使用传统的编程语言:如C、C+和Fortran更快地解决技术计算问题。matlab的应用范围非常广,包括信号和图像处理、通讯、控制系统设计、测试和测量、财务建模和分析以及计算生物学等众多应用领域。附加的工具箱单独提供的专用matlab 函数集扩展了matlab环境以解决这些应用领域内特定类型的问题。 matlab提供了很多用于记录和分享工作成果的功能。可以将您的matlab代码与其他语言和应用程序集成来分发您的matlab算法和应用。 此高级语言可用于技术计算,此开发环境可对代码、文件和数据进行管理,交互式工具可以按迭代的方式探查、设计及求解问题,数学函数可用于线性代数、统计、傅立叶分析、筛选、优化以及数值积分等二维和三维图形函数可用于可视化数据各种工具可用于构建自定义的图形用户界面各种函数可将基于matlab的算法与外部应用程序和语言:如C、C+、Fortran、Java、COM以及Microsoft Excel集成 。总而言之:matlab在计算科学、自然科学、社会科学等多方面都有很多应用。本文以matlab为工具主要研究它在GUI计算器设计方面的应用 关键词 MATMAB 计算器 GUISummarymatlab for algorithm development, data visualization, data analysis and numerical calculation of high-level technical computing language and interactive environment. Using MATLAB to the you can than with traditional programming languages such as C, C + + and Fortran the faster to solve technical computing problems Matlab application of a very wide scope including signal and image processing, communications, control system design, test and measurement, financial modeling and analysis, and computational biology and other many applications. Additional toolbox separate dedicated matlab function set expansion matlab environment the to solve specific types of problems in these application areas. matlab provides a function used to record and share their work. Your matlab code with other languages and application integration the to distribute your matlab algorithms and applications This high-level language for technical computing this development environment to code, documentation and data management, interactive tools can be an iterative manner exploration, design and solving the problem the mathematical function can be used in linear algebra, statistics, Fourier analysis,screening, optimization, and numerical integration 2D and 3D graphics functions for visualizing data a variety of tools for building custom graphical user interface a variety of functions can be based on the matlab algorithms with external applications and languages such asC and C + +, Fortran, the Java, COM, and Microsoft Excel the integration matlab applications in computational science natural Science the social science and other aspects have a lot of Matlab for tool the main study it in the GUI calculator design Keywords MATMAB calculator GUIIV三江学院毕业设计设计目的运用MATLAB实现MATLAB的GUI程序设计。1 题目分析1.1 课程设计的基本要求:A. 熟悉和掌握MATLAB 程序设计方法。B. 掌握MATLAB GUI 程序设计。1.2 课程设计的内容要求利用MATLAB 设计实现一个图形用户界面的计算器程序,要求实现:A. 具有友好的用户图形界面。实现十进制数的加、减、乘、除、乘方、取模等简单计算。B. 科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行。C. 能够保存上次历史计算的答案,先是答案存储器中得内容。D. 有清除键,能清除操作,并对不正确的表达式能指出其错误原因。 E. 独立存储器功能,使之可以直接输入存储器,可与存储器中的数值相加减。能够清除独立存储器中的内容。1.3 题目分析本题目通过MATLAB的gui程序设计较为简单,在gui设计中主要用到三种控件,显示框用到文本编辑框(edit text),说明框用到静态文本框(Static text),数字以及运算等按钮用到命令按钮(push button)。然后在通过各个按钮的回调函数,实现简单的计算功能。2 总体设计首先用MATLAB GUI功能,在绘制一个静态文本框和一个文本编辑框,以及33个命令按钮,调整好各控件大小、颜色,整体布局如图所示:然后通过双击个按钮来改写其属性,在m文件中编写其回调函数,最后在运行调试。3 具体设计3.1 各功能界面设计GUI设计界面3.2 各功能模块实现算法设计:A. 数字键设计:09以及小数点函数都一样,只是参数不同:global jjtextString = get(handles.text1,String);if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,1) ;elsetextString =strcat(textString,1);set(handles.text1,String,textString)endjj=0;B. 四则运算函数:textString = get(handles.text1,String);textString =strcat(textString,+);set(handles.text1,String,textString)C. 科学计算函数:textString = get(handles.text1,String);if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=sin(a);set(handles.text1,String,a)endD. 退格键:通过取屏幕值,计算出其字符长度,然后取其前N-1项的值来实现退格:global jjtextString = get(handles.text1,String);if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,0.) ;elsess=char(textString); l=length(textString); textString=ss(1:l-1);set(handles.text1,String,textString) endjj=0;E. 清屏键函数:set(handles.text1,String,0.) ;3.3 各模块实现结果A. 数字键:B. 四则运算函数:C. 科学计算函数:Sin1的计算结果=4 结果分析4.1 测试结果:(1+9)/5计算结果=23*4计算结果=12sin1计算结果=arcsin1计算结果= 经过计算,这些结果均与实际结果相吻合,计算器的功能实现的较为完好。4.2 问题和解决方法:a. 小数点可以连续输入。解决方法是:用strfind函数查看文本框里有几个小数点,如果已经有一个了,再按小数点就保持不变。按过运算符号后一个数不等于一个数,比如:输入1,按等号,会出来一个3,经过长时间分析得知,这是由于在按运算符号时,系统记录了文本框里的数但没有清空,才会出现这种问题。解决方法是再申请一个不同于加减乘除的另一个符号,并将按过运算符后记录的数值置0。5 心得体会通过本次的MATLAB课程设计,让我对MATLAB尤其是其GUI设计的功能有了进一步的了解,认识到了它功能的强大。在MATLAB简单计算器的设计中,了解了关于MATLAB图形用户界面的部分控件的使用方法;利用MATLAB的GUI提供的很多实用的控件,方便用于设计属于自己的图形界面。6 附录(源代码) fu ction varargout = calc(varargin)% CALC M-file for calc.fig% CALC, by itself, creates pushbutton20 new CALC or raises the existing% singleton*.% H = CALC returns the handle to pushbutton20 new CALC or the handle to% the existing singleton*.% CALC(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in CALC.M with the given input arguments.% CALC(Property,Value,.) creates pushbutton20 new CALC or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before calc_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to calc_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 calc % Last Modified by GUIDE v2.5 28-Jun-2011 09:08:35 % Begin initialization code - DO NOT EDIT%定义函数gui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, calc_OpeningFcn, . gui_OutputFcn, calc_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 code - DO NOT EDIT % - Executes just before calc is made visible.function calc_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to calc (see VARARGIN) % Choose default command line output for calchandles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes calc wait for user response (see UIRESUME)% uiwait(handles.figure1);%定义全局变量jj 用于数字的设定global jj ;%设置句柄,用于将按键接收的值返回给主程序set(handles.text1,String,0.);jj=0; % - Outputs from this function are returned to the command line.function varargout = calc_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout1 = handles.output; %按键 1 响应% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,1) ;elsetextString =strcat(textString,1);set(handles.text1,String,textString)endjj=0;%按键 2 响应 % - Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,2) ;elsetextString =strcat(textString,2);set(handles.text1,String,textString) endjj=0; %按键 3 响应% - Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,3) ;elsetextString =strcat(textString,3);set(handles.text1,String,textString) endjj=0;%按键 4 响应 % - Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,4) ;elsetextString =strcat(textString,4);set(handles.text1,String,textString) endjj=0;%按键 5 响应 % - Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,5) ;elsetextString =strcat(textString,5);set(handles.text1,String,textString) endjj=0; %按键 6 响应% - Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,6) ;elsetextString =strcat(textString,6);set(handles.text1,String,textString) endjj=0; %按键 7 响应% - Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,7) ;elsetextString =strcat(textString,7);set(handles.text1,String,textString) endjj=0; %按键 8 响应% - Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,8) ;elsetextString =strcat(textString,8);set(handles.text1,String,textString) endjj=0;%按键 9 响应 % - Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject handle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,9) ;elsetextString =strcat(textString,9);set(handles.text1,String,textString) endjj=0; %按键 0 响应% - Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA) global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,0.) ;elsetextString =strcat(textString,0);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject handle to pushbutton11 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);%strcmp(textString,0.)if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=0-a;set(handles.text1,String,a)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 pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jj textString = get(handles.text1,String);if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ; jj=1;elsetextString =strcat(textString,.);set(handles.text1,String,textString)end%按键/响应 % - Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)% hObject handle to pushbutton13 (see GCBO)% eventdata reserved - to be defined in pushbutton20 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) %按键(响应% - Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, eventdata, handles)% hObject handle to pushbutton13 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA) textString = get(handles.text1,String); if(strcmp(textString,0.)=1) set(handles.text1,String,() ;elsetextString =strcat(textString,();set(handles.text1,String,textString)end %按键*响应% - Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, eventdata, handles)% hObject handle to pushbutton15 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA) %endtextString = get(handles.text1,String);textString =strcat(textString,*);set(handles.text1,String,textString) %按键)响应% - Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);if(strcmp(textString,0.)=1) set(handles.text1,String,) ;elsetextString =strcat(textString,);set(handles.text1,String,textString)end%按键-响应 % - Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)% hObject handle to pushbutton17 (see GCBO)% eventdata reserved - to be defined in pushbutton20 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) %按键=响应% - Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)% hObject handle to pushbutton12 (see GCBO)% eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);% if(strcmp(textString,0.)=1)% set(handles.text1,String,0.) ;% else% pushbutton20 b c = strread(textString, %f %c %f);% clear ans;% % switch b% case *% ans=pushbutton20*c;% case /% if (c=0)% ans=Error Divided by zero;% else% ans=pushbutton20/c;% end% case -% ans=pushbutton
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年健康管理实务考试试题及答案解析
- 2025年建筑环境设计师专业水平检测试题及答案解析
- 2025年航空安全管理专家考试试题及答案解析
- 2025年机关消防演练测试题及答案
- 机电润滑基础知识培训课件
- 2025年企业员工安全考核题库及答案
- 2025年慈善基金会招聘笔试预测题
- 2025年安全生产安全文化测试题含答案
- 2025年工程造价师资格认证考试试题及答案解析
- 2025年复工复产安全培训测试题含答案
- 医院空气净化标准
- 2025高中英语学业水平考试会考复习必背词汇表
- 2025年高考日语试卷及答案详解
- 软件需求分析师岗位面试问题及答案
- 2025至2030中国军事上的人工智能行业发展趋势分析与未来投资战略咨询研究报告
- 二战历史教育
- 减盐减糖减油烹饪技巧培训
- 民航英语说课课件
- 教师数字提升培训课件
- 中西医结合医院“十五五”发展规划
- 消化性溃疡疾病的护理
评论
0/150
提交评论