matlab课程设计简单计算器的设计
(word完整版)用MATLAB GUI设计简单计算器

摘要基于MATLAB GUI的计算器设计是利用GUIDE创建图形用户界面进行计算器设计。
设计计算器时,主要是考虑到计算器的易用性、功能的常用程度进行计算器界面与功能的设计。
通过调整控件和文本的布局及颜色,使界面简单大方、布局合理,达到界面友好的效果。
计算器设计时主要利用到get和set两个函数进行各个控件属性值的传递和设置。
计算器实现的功能有:数字0~9和小数点的输入显示,平方、开平方和对数的输入显示。
进行四则运算、正弦计算、余弦计算、正切计算和余切计算,可以求阶乘、求百分数和求倒数。
可以进行括号及变量x与变量y的输入,结合坐标轴编辑框和曲线颜色编辑框实现函数的曲线绘制。
最后运行调试,实现基于MATLAB GUI的计算器的设计。
MATLAB GUI介绍MATLAB是美国MathWorks公司出品的商业数学软件,用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境。
MATLAB是matrix和laboratory两个词的组合,意为矩阵工厂,主要面对科学计算、可视化以及交互式程设计的高科技计算环境。
MATLAB是将数值分析、矩阵计算、科学数据可视化以及非线性动态系统的建模和仿真等诸多强大功能集成在一个易于使用的视窗环境中,为科学研究、工程设计以及必须进行有效数值计算的众多科学领域提供了一种全面的解决方案,并在很大程度上摆脱了传统非交互式程序设计语言的编辑模式,特别是所附带的30多种面向不同领域的工具箱支持,使得它在许多科学领域中成为计算机辅助设计和分析、算法研究和应用开发的基本工具和首选平台。
MATLAB的图形用户界面(Graphical User Interface,简称GUI,又称图形用户接口)是指采用图形方式显示的计算机操作用户界面。
与早期计算机使用的命令行界面相比,图形界面对于用户来说在视觉上更易于接受。
MATLAB的图形用户界(GUI)是由光标,窗口,菜单、文字说明等对象构成一个用户界面。
基于Matlab的简易计算器

工程设计报告设计题目:基于Matlab的简易计算器学院:专业:班级:学号:姓名:电子:日期:2015年12 月成绩:指导教师:. 西 安 电 子 科 技 大 学 电 子 工 程 学 院 工 程 设 计 任 务 书 学生 指导教师 职称 学生学号 专业 题目 基于Matlab 的简易计算器 任务与要求 任务如下: 利用MATLAB GUI 设计实现一个图形用户界面的计算器程序,实现: A.实现十进制数的加、减、乘、除、简单计算。
B. 科学计算函数,包括正弦、余弦、正切、余切、开方、指数等函数运行。
C. 有清除键,能清除操作。
要求如下: A .熟练掌握Matlab GUI 界面的设计与应用 B .最终计算器能够实现预期的相关功能开始日期 2015年 11月 日 完成日期 2016年1月 日课程设计所在单位本表格由电子工程学院网络信息中心 编辑录入 . …………………………装………………………………订………………………………线………………………………………………………………摘要基于Matlab GUI计算器设计时利用GUI的创建图像用户界面进行计算器设计。
设计计算器时,主要是考虑到计算器的易用性、功能的常用程度进行计算器界面与功能的设计。
通过调整控件和文本的布局及颜色,使界面简单大方、布局合理,达到界面友好的效果。
计算器设计时主要利用到get和set两个函数进行各个控件属性值的传递和设置。
计算器实现的功能有:数字0~9和小数点的输入显示,平方开方和对数的输入显示。
进行四则运算、正弦函数、余弦函数、正切函数以及反正弦函数、反余弦函数、反正切函数的计算等等。
最后运行调试,实现基于Matlab GUI的计算器的设计。
关键词:Matlab GUI 计算器AbstractsBased on Matlab GUI calculator design using the user interface to create images of GUI calculator design.Design calculator, mainly considering the ease of use, function calculators calculator interface and function of the common level of design.By adjusting the control and the layout of the text and color, make the interface simple and easy, rational layout, to achieve the effect of friendly interface.Calculator design used to get and set two main function for each attribute value transfer and control Settings.Calculator the functions are: 0 ~ 9, according to input and decimal square root and logarithm of input.Arithmetic, sine function and cosine function, tangent function and the arcsine function,arccosine function,the calculation of the arctangent function and so on.Finally running debugging, implementation design based on Matlab GUI calculator.Keywords: Matlab GUI calculator目录摘要 (4)Abstracts (4)目录 (6)第一章绪论 (8)1.MATLAB简介: (8)2.本文安排: (8)第二章GUI设计界面 (10)2.1打开GUI (11)2.2.添加按钮 (11)2.3.根据按钮的作用及视觉效果做一定的修改 (11)2.4.保存、添加功能函数 (12)2.4.1 数字键编写 (12)2.4.2 符号键的编写 (13)2.4.3 运算符“=”的编写 (13)2.4.4 按键“←back”的编写 (13)2.4.5 按键“清空”的编写 (14)2.4.6 按键“退出”的编写 (14)第三章计算器的使用和抽样检验 (15)3.1 除法运算(÷) (15)3.2 平方运算(^2) (15)3.3 函数cos (∏/3)的计算 (17)3.4 函数arcsin(∏/3)的计算 (17)3.5 以2为底的对数(log 2)的计算 (18)3.6 总结: (18)第四章特殊函数的源代码及总结 (19)函数代码及思路: (19)总结:问题及其优化 (21)第五章心得体会 (22)参考文献 (23)第一章绪论1.MATLAB简介:MATLAB是matrix和laboratory两个词的组合,意为矩阵工厂(矩阵实验室)。
matlab课程教学设计(简单计算器的设计)

matlab课程设计报告题目简易计算器的设计学院电子信息工程学院专业电子信息学生姓名和学号指导教师一、选题目的及意义GUI的广泛应用是当今计算机发展的重大成就之一,它极大地方便了非专业用户的使用。
人们从此不再需要死记硬背大量的命令,取而代之的是可以通过窗口、菜单、按键等方式来方便地进行操作,而在matlab有很简单的gui设计工具,我们可以通过这个工具轻松地构建我们想要的程序,从而实现与用户的信息交互。
本次课程设计是使用了matlab中的guide生成了简单的计算器程序。
二、源代码function varargout = Calculator(varargin)%Simple Calculator%@Anhui University% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @Calculator_OpeningFcn, ...'gui_OutputFcn', @Calculator_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{:});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.% 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 command line arguments to Calculator (see VARARGIN)% Choose default command line output for Calculatorhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes Calculator wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = Calculator_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 of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.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,'string');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 MATLABtextstring=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 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,'3');set(handles.text1,'string',textstring)% --- Executes on button press in p4.function p4_Callback(hObject, 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',textstring)% --- 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,'string');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 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 reserved - to be defined in a future version of MATLABtextstring=get(handles.text1,'string');textstring=strcat(textstring,'7');set(handles.text1,'string',textstring)% --- Executes on button press in p8.function p8_Callback(hObject, 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',textstring)% --- 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,'string');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 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 p0.function p0_Callback(hObject, eventdata, handles)% hObject handle to p0 (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,'0');set(handles.text1,'string',textstring)% --- Executes on button press in sub.function sub_Callback(hObject, eventdata, handles)% hObject handle to sub (see GCBO)% eventdata reserved - to be defined in a future version of MATLABtextstring=get(handles.text1,'string');textstring=strcat(textstring,'-');set(handles.text1,'string',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.text1,'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 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 (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=eval(textstring);set(handles.text1,'string',textstring)% --- Executes on button press in clear.function 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, 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)% 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_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.可进行清零,退出等三、界面设计及运行结果1-1. GUIDE 设计界面1-2.进入程序初始状态1-3.简单的实例测试.\五、心得及体会通过这次matlab课程设计,让我对matlab有了更深的了解。
用MATLAB制作一简单计算器

这个matlab课程设计是在GUI环境下生成的。
开启MATLAB 7.0 软件,在命令窗口输入guide,即可进入GUI环境。
实验目的:(1)熟悉GUI环境,并在该环境中制作一个简单的计算器,起功能有加,减,乘,除, cos, sin, tan。
(2)熟悉matlab软件的制作。
实验内容及结果:进入GUI环境中双击Blank GUI (Default)出现一个窗口在该窗口中首先制作一个计算器界面如下所示:红色的是静态编辑框,其余的是按钮。
下面我们来分析一下功能函数:textString = get(handles.text1,'String');textString = strcat(textString,'1');set(handles.text1,'String',textString)这是使用句柄handles指向对象text1,并以字符串形式来存储数据文本框text1的内容,并存储数个“1”,然后由set(handles.text1,'String','textString'在text1中输出。
同理,分别在function pushbuttonone~zero_Callback(hObject, eventdata, handles)下给1~0数字按键下编写此类程序。
function pushbuttonjia_Callback(hObject, eventdata, handles) textString = get(handles.text1,'String');textString =strcat(textString,'+');set(handles.text1,'String',textString)strcat的作用是将两个字符串连接起来,就是在已输入的存储数据textString 后添加“+”进行运算。
Matlab课程设计报告(简单计算器)

1、设计目的运用MATLAB实现MATLAB的GUI程序设计。
2、题目分析2.1课程设计的基本要求:A. 熟悉和掌握MATLAB 程序设计方法。
B. 掌握MATLAB GUI程序设计。
2.2课程设计的内容要求利用MATLAB GUI设计实现一个图形用户界面的计算器程序,要求实现:A. 具有友好的用户图形界面。
实现十进制数的加、减、乘、除、乘方、取模等简单计算。
B. 科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行。
C. 能够保存上次历史计算的答案,显示答案存储器中的内容。
D. 有清除键,能清除操作。
E. 独立存储器功能,使之可以直接输入存储器,可与存储器中的数值相加减。
能够清除独立存储器中的内容。
2.3题目分析本题目通过MATLAB的GUI程序设计较为简单,在GUI设计中主要用到三种控件,显示框用到文本编辑框(edit text),说明框用到静态文本框(Static text),数字以及运算等按钮用到命令按钮(push button)。
然后再通过各个按钮的回调函数,实现简单的计算功能。
3、总体设计首先用MATLAB GUI功能,在绘制一个静态文本框和一个文本编辑框,以及32个命令按钮,调整好各控件大小、颜色,整体布局如图所示:然后通过双击个按钮来改写其属性,在m文件中编写其回调函数,最后在运行调试。
4、具体设计4.1 各功能界面设计GUI设计界面:4.2 各功能模块实现算法设计:A. 数字键设计:0—9以及小数点函数都一样,只是参数不同: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)end或textString=handles.text1;textString=sin(str2num(get(handles.text1,'String'))*pi/180);set(handles.text1,'String',num2str(textString))D. 退格键:通过取屏幕值,计算出其字符长度,然后取其前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.') ;F.右键函数:gtext('大家好;我是智能机器人-my name is seven');close(gcf);4.3 各模块实现结果A. 数字键:B. 四则运算函数:C. 科学计算函数:Sin45的计算结果=经过计算,这些结果均与实际结果相吻合,计算器的功能实现的较为完好。
基于matlab的课程课时计算器设计

基于matlab的课程课时计算器设计设计一个基于MATLAB的课程课时计算器,可以用来计算课程总时间、每周课时和平均每节课的时间。
这个计算器可以帮助老师或学生更好地管理课程时间,确保每个课程的时间安排合理。
首先,我们需要用户输入每个课程的名称、每周上课次数和每节课的时间。
为了实现这个功能,我们可以使用MATLAB中的输入函数来获取用户的输入信息。
接下来,我们需要将用户输入的信息存储在一个数组中,以便于后面的计算。
我们可以使用MATLAB中的数据结构来实现这个功能。
具体来说,我们可以创建一个结构体数组,每个结构体包含课程的名称、每周上课次数和每节课的时间。
在计算过程中,我们需要用到循环语句来遍历结构体数组并进行计算。
我们可以使用for或while循环来实现这个功能。
首先,我们可以使用for循环来遍历结构体数组并计算课程总时间。
在每次迭代中,我们可以将每个课程的每周上课次数乘以每节课的时间,然后将结果累加到一个变量中。
接下来,我们可以使用同样的方法使用for循环来计算每周总课时。
在每次迭代中,我们可以将每个课程的每周上课次数累加到一个变量中。
最后,我们可以根据前两个计算结果计算平均每节课的时间。
我们可以将总时间除以总课时,得到每节课的平均时间。
在计算完成后,我们可以使用MATLAB中的输出函数来显示计算结果,并保存在一个文件中以便之后查看。
此外,我们还可以考虑一些额外的功能来提升这个计算器的实用性。
例如,我们可以添加一个课程表功能,让用户可以方便地查看每天的课程安排。
我们还可以添加一个报警功能,当用户接近或超过每周总课时限制时,系统可以发出提醒。
这些功能可以通过使用MATLAB中的图形用户界面(GUI)来实现。
综上所述,一个基于MATLAB的课程课时计算器可以帮助用户更好地管理课程时间。
通过输入课程的名称、每周上课次数和每节课的时间,计算器可以计算总时间、每周总课时和平均每节课的时间。
同时,通过添加额外的功能如课程表和报警功能,计算器的实用性可以进一步提升。
电信12-1班 1206110109matlab简易计算器设计步骤与回调函数设计

简易算术计算器的设计一、算术计算器的功能:能进行简单的加、减、乘、除法,sin,cos,tan,x^2,squrt运算,输入文本框显示为常量多项式,输出文本框显示为精确到小数点后十位的数值。
计算器包含十个数字键0~9、小数点键“.”、小括号键“(”“)”、运算符号、清屏键、退格键、退出键等。
二、设计思路:每按下一个数字键或者符号键的时候,利用get(handles.edit1,'string')获取当前输入文本框edit1的string属性,并通过字符串合并函数strcat()将当前输入文本框edit1的字符型string属性与按键的字符型string属性合并成字符串,然后利用属性设置函数set(); 将合并后的字符串返回到输入文本框edit1的string属性。
当输入结束,用户按下等号的时候,采用x=get(handles.edit1,'string')获取当前输入文本框edit1的string属性,然后利用字符串执行命令y1=eval(x)计算输入文本框的表达式,得到的结果是字符型常量;然后利用字符串输出格式控制函数y=sprintf('%.10f',y1)使输出结果精确到小数点后十位;最后利用属性设置函数set(handles.edit2,'string',y)将转换后的字符串返回到输出文本框edit2的string属性。
三、设计步骤:1、运行matlab2014a,进入主界面。
2、输入guide,进入GUI开发环境。
3、创建控件:按钮包括数字0~9、运算符“+ - * /”、功能键等26个,输入和动态静态文本框,显示文字的静态文本框四个等。
4、对控件单击右键弹出菜单,选择属性检查器,设置控件属性。
5、选择工具栏上的对齐对象按键,调整控件布局。
6、选择工具栏上的Tab 顺序编辑器按键,通过和设置各控件的Tab顺序。
7、设计菜单:在GUI开发环境下,选择工具栏上的进入菜单编辑器,分别选择和创建主菜单和子菜单。
基于MATLAB-GUI的简单计算器

基于MATLAB-GUI的简单计算器设计题目:计算器完成一个简单的计算器。
要求(但不限于):GUI上具有数字键盘输入区域,能够进行加、减、乘、除、三角函数等基础运算。
界面简洁、美观可能需要的控件:Push ButtonEdit TextPop-up Menu1 功能介绍本程序是一个简单的计算器程序,使用MATLAB软件编写完成。
主要具有加、减、乘、除、三角函数等基础运算,并通过GUI进行程序使用的交互。
程序交互界面如下:图1 程序的交互界面2 功能实现首先用MATLAB GUI功能,在绘制一个动态文本框和一个文本编辑框,以及25个命令按钮,调整好各控件大小、颜色,整体布局如图所示:备注:软件版本:MATLAB R2011b2.1 布局GUI1、打开MATLAB,在Guide中新建FIG文件2、然后双击“Blank GUI(Default)”或单击OK键出现GUI窗口3、添加按钮和动态文本框4、根据按钮的作用及视觉效果做一定的修改对按钮的字符串大小、颜色进行设置,对按钮的位置进行排布,尽量使按钮集中在动态文本框下面。
最终设置的动态文本框为灰色,其他按钮均为蓝色。
5、保存、添加功能函数将做好的按钮及动态文本框保存后自动弹出Editor的M文本,然后对相应的pushbutton添加功能函数。
以下是相应按钮的功能函数。
(1)数字按键编写。
在function pushbutton1_Callback(hObject, eventdata, handles)下输入:global jja=get(handles.edit1,'String');if(strcmp(a,'0.')==1)&&(jj==0)set(handles.edit1,'String','0.')elsea=strcat(a,'0')set(handles.edit1,'String',a)endjj=0这是使用句柄handles指向对象edit1,并以字符串形式来存储数据文本框edit1的内容,并存储数个“0”,然后由set(handles.edit1,'String',a)在edit1中输出。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
matlab课程设计报告题目简易计算器的设计学院电子信息工程学院专业电子信息学生姓名和学号指导教师一、选题目的及意义GUI的广泛应用是当今计算机发展的重大成就之一,它极大地方便了非专业用户的使用。
人们从此不再需要死记硬背大量的命令,取而代之的是可以通过窗口、菜单、按键等方式来方便地进行操作,而在matlab有很简单的gui设计工具,我们可以通过这个工具轻松地构建我们想要的程序,从而实现与用户的信息交互。
本次课程设计是使用了matlab中的guide生成了简单的计算器程序。
二、源代码function varargout = Calculator(varargin)%Simple Calculator%@Anhui University% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @Calculator_OpeningFcn, ...'gui_OutputFcn', @Calculator_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{:});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.% 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 command line arguments to Calculator (see VARARGIN)% Choose default command line output for Calculatorhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes Calculator wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = Calculator_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 of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.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,'string');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 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 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,'3');set(handles.text1,'string',textstring)% --- Executes on button press in p4.function p4_Callback(hObject, 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',textstring)% --- 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,'string');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 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 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,'7');% --- Executes on button press in p8.function p8_Callback(hObject, 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',textstring)% --- 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,'string');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 structure with handles and user data (see GUIDATA)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 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(hObject, 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',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.text1,'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 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 (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=eval(textstring);set(handles.text1,'string',textstring)% --- Executes on button press in clear.function 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, 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)% 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_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.可进行清零,退出等三、界面设计及运行结果1-1. GUIDE 设计界面1-2.进入程序初始状态1-3.简单的实例测试五、心得及体会通过这次matlab课程设计,让我对matlab有了更深的了解。