MATLAB GUI编程实例(加法器)
(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的计算器制作
基于MATLA啲计算器制作从入门到高级项目一、建立GUI框架1,双击MATLAB图标(本实例使用的是MATLAB R2014 ,打开软件H 22,打开GUI操作界面。
有两种方式:a、在命令行窗口输入guide,然后点击回车。
b、先点击新建图标,在选择‘图形用户界面’。
得到如下窗口:左上方有两个按钮:‘新建GUI',‘打开现有GUI' 对于‘新建GUI':下方的选择框内有你可以选择建立的GUI类型,对于初学者一般选择第一个。
下方是用来设置保存文件位置的。
对于‘打开现有GUI':初学者可能会在网上下载一些GUI源程序,使用‘打开现有GUI',再浏览到文件所在位置便可。
3、构建GUI框架:在选择新建GUI并且确定后,会弹出如下窗口:在窗口的左边会有很多选项,可以一个个拖动编辑框内;是不是发现这些选项发挥的作用刚好就是我们平常打开一个网页或者一个软件进行操作时的选择按钮。
比较常见的有:按钮、单选按钮、拖动条、弹出式菜单等。
看到这里细心地朋友就会发现,MATLAB GU似乎可以开发出大型软件哦,只要你有足够的想象力,当你从一个小白进阶到 一个高手之后,你可以做到的。
本次计算器制作只需要用到静态文本(或者是动态文本) 用来做显示器,按钮(用来操作)。
也可以添加一个面板 用来修饰。
这个属性框比较复杂,没有必要一个个说清楚(有兴趣的 可以自己研究,其实理解起来也挺简单的)本次计算器制作,我们只需要知道以下几个:在拖出的选项上双击,会得出该选项的属性栏,比如说 双击一个按钮选项,你会得到:劃灿I ■ ■E- Backqrowrdcolcwe 匚二1二Beir^De^eted! dt *也艺|M> doubleForTCAngl*[0 0^2 23®旬MHrruil*船5eriF> Fonduer F^nHlnit>1 Fcn^Wdi^lEiwmal4 出IForie-^rDLindCpIcr f ■HnrdlllcVr^jbpE * HlTeitE| HofiJCirl^lAl! fomentLWter■■LWirUpable3|*mbenTopL91.9匚3整 C-illbirlc□ippingi C -TMtHFcri C'EleteFcn EriacronIt RfirtwnMna 、BackgroundColor 取值为颜色的预定义字符或RGB数值;缺省(就是默认的意思)值为浅灰色;b 、 ForegroundColor 取值为颜色的预定义字符或 数值,该属性定义控件对象标题字符的颜色;缺省值 为黑色;c 、 String 取值为字符串矩阵或块数组,定义控件对 象标题或选项内容;d 、 FontName 取值为控件标题等字体的字库名; e 、 FontSize 取值为数值,控制字体大小;f 、 Tag 取值为字符串,定义了控件的标识值,在任何 程序中都可以通过这个标识值控制该控件对象;g 、 Style 取值可以是 pushbutton (缺省值), radiobutton, checkbox, edit, text, slider, frame, popupmenu 或 listbox ;项目二、简单加法器的制作1、框架准备 ‘加法器':使用静态文本,在 string 处将文本修改为 (加法器),在 fontsize 可修改字体大小,在 BackgroundColor 处可修改背景颜色。
用MATL制作一简单计算器
这个matlab课程设计是在GUI环境下生成的.开启MATLAB 软件,在命令窗口输入guide,即可进入GUI环境.实验目的:1熟悉GUI环境,并在该环境中制作一个简单的计算器,起功能有加,减,乘,除, cos,sin, tan.2熟悉matlab软件的制作.实验内容及结果:进入GUI环境中双击Blank GUI Default出现一个窗口在该窗口中首先制作一个计算器界面如下所示:红色的是静态编辑框,其余的是按钮.下面我们来分析一下功能函数:textString = get,'String';textString = strcattextString,'1';set,'String',textString这是使用句柄handles指向对象text1,并以字符串形式来存储数据文本框text1的内容,并存储数个“1”,然后由set,'String','textString'在text1中输出.同理,分别在function pushbuttonone~zero_CallbackhObject, eventdata, handles下给1~0数字按键下编写此类程序.function pushbuttonjia_CallbackhObject, eventdata, handlestextString = get,'String';textString =strcattextString,'+';set,'String',textStringstrcat的作用是将两个字符串连接起来,就是在已输入的存储数据textString后添加“+”进行运算.然后执行set,'String',textString.符号键‘-’、‘’、‘/’与‘+’的运算函数类似.function cos_CallbackhObject, eventdata, handles textString=;textString=cosstr2numget,'String'pi/180;set,'String',num2strtextStringget,'String'pi/180是把角度转换为弧度,这样在编程环境中才能识别,cos才能起作用.然后执行set函数,把结果输出来.同理在sin,tan的回调函数中夜输入相应的函数,只需把textString=cosstr2numget,'String'pi/180;中的cos改为sin,tan即可.function dengyu_CallbackhObject, eventdata, handles textString = get,'String';s =evaltextString;set,'String',s“eval”的作用是将符号表达式转换成数值表达式.再由set,'String',s输出.现在就是操作了.保存界面后出现点击f找到相应的函数,然后再点击它,光标会自动跳到相应的函数,在函数的下面插入如上的相应代码.做完了以上步骤,下面我们开始运行加法:结果是:减法的运算:结果是;乘法的运算:结果是:除法的运算:结果是:Sin的运算:结果是:Cos的运算:结果是:Tan的运算:结果是:以上就是制作计算器的全过程.还要详细补充的是在GUI双击Blank GUI Default,在出现的窗口中拉动所需的用键后双击它会出现找到,可以改变字体的大小.找到可以改变框的颜色.找到可以清空框里的字,还可以输入所需相应的字符.这里可以修改相应的函数名,便于后面出入代码.。
matlab中加法运算
matlab中加法运算Matlab是一种强大的数值计算和数据可视化工具,它提供了丰富的函数和工具箱,方便用户对数据进行加法运算和相关的数学操作。
本文将介绍在Matlab中进行加法运算的方法和技巧。
我们需要了解Matlab中的基本数据类型。
Matlab支持多种数据类型,包括数字、字符串、矩阵等。
对于数字类型,可以直接使用加号(+)进行加法运算。
例如,我们可以计算两个数字的和:a = 3;b = 4;c = a + b;在上述代码中,我们定义了两个变量a和b,分别赋值为3和4。
然后使用加号将它们相加,并将结果赋值给变量c。
通过输出变量c 的值,我们可以得到两个数字的和。
在Matlab中,使用分号(;)可以抑制输出结果,如果不希望输出结果,可以在代码末尾加上分号。
除了数字类型,Matlab还支持字符串类型。
对于字符串类型,加法运算表示字符串的拼接。
例如,我们可以将两个字符串拼接在一起:str1 = 'Hello';str2 = 'World';str3 = str1 + ' ' + str2;在上述代码中,我们定义了两个字符串变量str1和str2,分别赋值为'Hello'和'World'。
然后使用加号将它们拼接在一起,并添加一个空格,将结果赋值给变量str3。
通过输出变量str3的值,我们可以得到拼接后的字符串。
除了基本数据类型,Matlab还支持矩阵和向量的加法运算。
在Matlab中,可以使用矩阵和向量进行加法运算,得到对应位置上的元素相加的结果。
例如,我们可以计算两个矩阵的和:A = [1 2; 3 4];B = [5 6; 7 8];C = A + B;在上述代码中,我们定义了两个2×2的矩阵A和B,然后使用加号将它们相加,并将结果赋值给矩阵C。
通过输出矩阵C的值,我们可以得到两个矩阵对应位置上的元素相加的结果。
实验4、matlab的计算可视化和GUI设计
p345subplot(2,2,1)t1=0:0.1:2;y1=sin(2*pi*t1);plot(t1,y1);title('y=sin(2\pit)')练习:subplot(2,2,2)t2=0:0.1:2;y2=[exp(-t2);exp(-2*t2);exp(-3*t2)]; plot(t2,y2)axis([0 2 -0.2 1.2]);title('y=e-t,y=e-2t,y=e-3t')练习:subplot(2,2,3);t3=[0 1 1 2 2 3 4]; y3=[0 0 2 2 0 0 0]; plot(t3,y3);axis([0 4 -0.5 3]); title('脉冲信号')练习:subplot(2,2,4);t4=0:0.1:2*pi;plot(sin(t4),cos(t4));axis([-1.2 1.2 -1.2 1.2]);axis equal;title('圆')练习:P346x=0:0.1:20;zeta=0y1=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));plot(x,y1)zeta=0.3;y2=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));hold onplot(x,y2,'r:')zeta=0.5;y3=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));plot(x,y3,'g*')zeta=0.707;y4=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));plot(x,y4,'m-')title('二阶系统曲线')legend('\zeta=0','\zeta=0.3','\zeta=0.5','\zeta=0. 707')grid ongtext('\zeta=0')gtext('\zeta=0.3')gtext('\zeta=0.5')gtext('\zeta=0.707')ginput(3)zeta =ans =2.6037 0.903513.1106 2.00294.2166 1.0380P347h_fig=gcfh_axis=gcah_line1=gcoh_title=get(gca,'title')h_text2=findobj(h_fig,'string','\zeta=0.3') h_fig =1h_axis =151.0018h_line1 =1h_title =152.0018h_text2 =Empty matrix: 0-by-1set(h_line1,'linewidth',5)set(h_axis,'xgrid','off')set(gca,'ytick',[0 0.25 0.5 1.0 1.25 1.5 1.75 2.0])set(h_title,'color','red','fontsize',13)set(h_text2,'color','red')??? Undefined function or variable 'h_axis'.P349x=0:0.1:20;y1=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));y2=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));y3=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));y4=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt( 1-zeta^2)*x+acos(zeta));y=[y1;y2;y3;y4];z=[ones(size(x))*0;ones(size(x))*0.3;ones(siz e(x))*0.5;ones(size(x))*0.707];plot(x,x,x,x)surf(x,x,x,x)??? Input argument "n" is undefined.Error in ==> zeta at 12Z = double(zeta(sym(n),sym(X)));P350x=0:0.3:2*pi;y=sin(x);subplot(2,2,1)bar(x,y,0.5)axis([0,2*pi,-1.2,1.2])subplot(2,2,2)fill(x,y,'r')subplot(2,2,3)stairs(x,y)subplot(2,2,4)stem(x,y)P350guide。
MATLAB GUI编程实例(加法器)
Matlab GUI编程实现加法器一.首先我们新建一个GUI文件:File/New/GUI,选择Blank GUI(Default),如下图所示二.进入GUI开发环境以后添加两个编辑文本框,6个静态文本框和一个按钮,布置如下图所示:布置好各控件以后,我们就可以来为这些控件编写程序来实现两数相加的功能了。
三.我们先为数据1文本框添加代码;点击上图所示红色方框,选择edit1_Callback,或者是在数据1文本框出右键选择View Callbacks–>Callback,光标便立刻移到下面这段代码的位置:function edit1_Callback(hObject,eventdata,handles)%hObject handle to edit1(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%Hints:get(hObject,'String')returns contents of edit1as text %str2double(get(hObject,'String'))returns contents of edit1 as a double然后在上面这段代码的下面插入如下代码:input=str2num(get(hObject,'String'));if(isempty(input))set(hObject,'String','0');endguidata(hObject,handles);这段代码使得输入被严格限制,我们不能试图输入一个非数字。
四.为edit2_Callback添加同样一段代码。
基于matlab的计算器编程附代码
1.需求分析本次的实验要求是设计一个计算器,主要功能如下:(1)实现基本数学运算(加减乘除等),而且要能进行混合运算(2)实现部分函数功能,如求平方根、求倒数等(3)能实现小数运算界面与标准计算器界面类似根据要求以及以前的学习情况,决定使用matlab进行编程。
Matlab强大的计算功能以及便捷的GUI设计,可以较为简便的实现所要求的功能。
按照要求,数据输入和输出支持小数点,支持四则混合运算,决定使用如下几个数据进行分析:(1+3)*5Sqrt(4)1/2Sin4用以检验是否可以进行加减乘除四则运算、平方根、倒数、正弦的运算。
2.程序设计M atlab的程序设计较为简便,用GUI设计出一个计算器的模型,然后系统会自动生成一个框架,在框架中,写入每一个按键对应的程序就可以实现功能。
3.调式分析编程的过程中遇到的问题不是很多,基本就是找要实现各个功能的子程序,通过上网和去图书馆,加上自己的编写,终于实现了实验要求的功能。
但是有一点很重要,matlab不支持中文,所以从路径到文件名必须是全英文的,不然就无法识别。
此外,给每个按键命名也是很重要的,不然在生成的程序框架里面,就无法识别各个按键的作用,编写程序的时候也就无法做到一一对应。
4.使用说明程序的使用比较简单,由于是可视化界面,直接打开matlab,然后建立一个GUI 工程,再打开生成的fig文件,就是一个计算器的界面,直接按照市面上卖的计算器的方法,按键使用即可。
5.测试结果计算结果为204sqrt=2Sin4结果为1/2=0.5经过计算,这些结果均与实际结果相吻合,计算器的功能实现的较为完好。
6.心得体会本次试验由于不限制语言,于是计算功能强大,操作简便的matlab变成了首选,matlab的GUI设计,操作是较为简单的,首先建立一个GUI工程,然后用可视化界面,设计出计算器的大致外观,为每一个按键设置预计的功能,然后就是将对应的函数写到框架生成的程序中,然后每个按键就可以实现对应的功能。
[知识]matlab简单加法计算
MATLAB---GUI(1)简单加法计算(2011-04-27 00:36:46)转载分类:matlab标签:matlabguiitlearn matlab--gui(1)参考:matlab--gui教程一、启动matlab,打开gui编辑器:matlab下:File-->New-->GUI弹出对话框,选择Blank GUI(default)。
在主窗口上绘制两个标签(static text),三个文本框(edit text)以及一个按钮(push button),如下图:对界面进行一下修改,双击各个控件在弹出的属性窗口,将三个文本框的string属性都修改为0,将两个标签修改为“+”和“=”,将按钮的string属性修改为“计算”,修改完成后界面如下图所示,界面字体可以通过控件的fontsize属性修改。
为了便于在编写程序的时候区分各个控件,可以修改各个控件的唯一标示(tag 属性),三个文本框默认是(edit1,edit2和edit3),修改为edit_num1, edit_num2和edit_total,修改完成后,可以运行预览一下界面了,点击下图所示的绿色箭头此时为一个静态界面,是没有任何响应的,点击按钮是不会有变化的,现在我们就进行后台代码的编写了.编写M文件代码,在界面设计器上选中“计算”按钮,然后鼠标右键,在弹出的对话框上选择“callback”,弹出m文件编辑器,并自动生成了响应函数名。
在该函数下面来写点击按钮的响应函数,代码如下% 获取文本框内容a = get(handles.edit_num1,'String');b = get(handles.edit_num2,'String');% 字符串转换为实数total = str2double(a) + str2double(b);% 将实数转换为字符串c = num2str(total);%将字符串赋值会文本框set(handles. edit_total,'String',c);guidata(hObject, handles); %更新结构体然后进行保存,通过m editor可以对程序进行调试,我们这儿直接运行一下。
用MATLAB做的 一个计算器
一、布局GUI。
1.打开Matlab,输入Guide 回车或者在工具栏上点击图标出现Guide 窗口:2.然后双击“Blank GUI(Default)”出现GUI窗口3.添加按钮4.根据按钮的作用及视觉效果做一定的修改把按钮的字符串大小、颜色进行设置,对按钮的位置进行排布,尽量使按钮集中在静态文本框下面。
最终设置的静态文本框为白色,其他按钮均为分红色。
5.保存、添加功能函数把做好的按钮及静态文本框保存后自动弹出Editor的M文本,对然后对相应的pushbutton添加功能函数。
以下是相应按钮的功能函数。
(1)数字按键编写。
在function pushbutton1_Callback(hObject, eventdata, handles)下输入:textString = get(handles.text1,'String');textString =strcat(textString,'0');set(handles.text1,'String',textString)这是使用句柄handles指向对象text1,并以字符串形式来存储数据文本框text1的内容,并存储数个“0”,然后由set(handles.text1,'String','textString'在text1中输出。
同理,分别在function pushbutton2~10_Callback(hObject, eventdata, handles)下给1~9数字按键下编写此类程序。
(2).符号键:function pushbutton12_Callback(hObject, eventdata, handles)textString = get(handles.text1,'String');textString =strcat(textString,'+');set(handles.text1,'String',textString)strcat的作用是将两个字符串连接起来,就是在已输入的存储数据textString 后添加“+”进行运算。
matlab加减乘除运算
matlab加减乘除运算
Matlab是一种流行的科学计算软件,它可以进行各种数学运算,包括加减乘除运算。
在Matlab中,加法和减法运算可以使用'+'和'-'符号完成,乘法和除法运算可以使用'*'和'/'符号完成。
下面是一些示例代码,演示如何在Matlab中进行加减乘除运算:
加法运算:
a = 5;
b = 10;
c = a + b;
disp(c);
这个代码将输出15,因为a和b的值相加得到15,然后将结果赋给变量c。
减法运算:
a = 20;
b = 5;
c = a - b;
disp(c);
这个代码将输出15,因为a和b的值相减得到15,然后将结果赋给变量c。
乘法运算:
a = 3;
b = 4;
c = a * b;
disp(c);
这个代码将输出12,因为a和b的值相乘得到12,然后将结果赋给变量c。
除法运算:
a = 10;
b = 2;
c = a / b;
disp(c);
这个代码将输出5,因为a除以b得到5,然后将结果赋给变量c。
需要注意的是,在进行除法运算时,如果除数为0,则会出现错误,需要避免这种情况的发生。
matlab制作的简易计算器
Matlab大作业——简易计算器一.实现的功能简易计算器能够计算简单的加减乘除,能够将计算过程和结果显示出来,并且能够清空和删除数字。
二.实现方式通过Matlab中的GUI接口设计这个简易计算器,通过GUI中的pushbottom设计输入数字的键和加减乘除等于等键,然后通过edit text设计显示屏。
更改回调函数实现相关的计算功能。
三.程序分析0~9数字键的代码设置%全局变量locaval用于存储用户输入的多位数值%全局变量gloval2用于存储待处理的第二位数值function pushbutton1_Callback(hObject, eventdata, handles)global locaval;a = get(handles.pushbutton1,'String');locaval=strcat(locaval,a);set(handles.text1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);加减乘除键的代码设置%全局变量flagnum存储运算符标志%全局变量global1用于储存第一个待处理数值function pushbutton10_Callback(hObject, eventdata, handles)a = get(handles.pushbutton10,'String');b = get(handles.text1,'String');set(handles.text1,'String',a);global flagnumglobal gloval1global locavallocaval=' ';flagnum=1;gloval1=b;guidata(hObject, handles);等号键功能的实现%根据flagnum运算标志用switch决策语句实现相应计算%需注意相应数据类型的转化function pushbutton17_Callback(hObject, eventdata, handles) global flagnumglobal gloval1global gloval2global locavallocaval=' ';gloval1=str2num(gloval1);gloval2=str2num(gloval2);case1=gloval1/gloval2;case2=gloval1*gloval2;case3=gloval1-gloval2;case4=gloval1+gloval2;case1=num2str(case1);case2=num2str(case2);case3=num2str(case3);case4=num2str(case4);switch flagnum;case 1set(handles.text1,'String',case1);case 2set(handles.text1,'String',case2);case 3set(handles.text1,'String',case3);case 4set(handles.text1,'String',case4);endguidata(hObject,handles)Backspace键的代码设置%算法实现:MA TLAB是用矩阵存储数据的,相应的可以取文本框的前N-1实现其功能function pushbutton19_Callback(hObject, eventdata, handles)textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)set(handles.text1,'String','0.') ;elsess=char(textString);l=length(textString);textString=ss(1:l-1);set(handles.text1,'String',textString)endguidata(hObject,handles)清除按钮函数function pushbutton20_Callback(hObject, eventdata, handles)global locavallocaval=' ';set(handles.text1,'String','0.');guidata(hObject,handles)四.程序展示function varargout = jisuanji(varargin)% JISUANJI MATLAB code for jisuanji.fig% JISUANJI, by itself, creates a new JISUANJI or raises the existing% singleton*.%% H = JISUANJI returns the handle to a new JISUANJI or the handle to% the existing singleton*.%% JISUANJI('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in JISUANJI.M with the given input arguments.%% JISUANJI('Property','Value',...) creates a new JISUANJI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before jisuanji_OpeningFcn gets called. An % unrecognized property name or invalid value makes propertyapplication% stop. All inputs are passed to jisuanji_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 edit1 to modify the response to help jisuanji% Last Modified by GUIDE v2.5 04-Jun-2013 16:55:11% Begin initialization code - DO NOT EDITglobal gloval1;global gloval2;global flagnum;global locaval;gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @jisuanji_OpeningFcn, ...'gui_OutputFcn', @jisuanji_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 jisuanji is made visible.function jisuanji_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 jisuanji (see VARARGIN)% Choose default command line output for jisuanjihandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes jisuanji wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = jisuanji_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;function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as edit1 % str2double(get(hObject,'String')) returns contents of edit1 as a doubleglobal locavallocaval=str2num(locaval);locaval=1/locaval;set(handles.edit1,'String',locaval);locaval=' ';guidata(hObject,handles)% --- Executes during object creation, after setting all properties. function edit1_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 CreateFcnscalled% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');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 structure with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton3,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- Executes on button 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) global locaval;a = get(handles.pushbutton4,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton5,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- 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 % handles structure with handles and user data (see GUIDATA)a = get(handles.pushbutton6,'String');b = get(handles.edit1,'String');set(handles.edit1,'String',a);global flagnumglobal gloval1global locavallocaval=' ';flagnum=1;gloval1=b;guidata(hObject, handles);% --- Executes on 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) global locaval;a = get(handles.pushbutton7,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton8,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- 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 % handles structure with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton9,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- Executes 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)a = get(handles.pushbutton10,'String');b = get(handles.edit1,'String');set(handles.edit1,'String',a);global flagnumglobal gloval1global locavallocaval=' ';flagnum=2;gloval1=b;guidata(hObject, handles);% --- Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject 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) global locaval;a = get(handles.pushbutton11,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- 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 of MATLAB % handles structure with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton12,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- 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 with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton13,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, eventdata, 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)a = get(handles.pushbutton14,'String');b = get(handles.edit1,'String');set(handles.edit1,'String',a);global flagnumglobal gloval1global locavallocaval=' ';flagnum=3;gloval1=b;guidata(hObject, handles);% --- Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)a = get(handles.pushbutton16,'String');b = get(handles.edit1,'String');set(handles.edit1,'String',a);global flagnumglobal gloval1global locavallocaval=' ';flagnum=4;gloval1=b;guidata(hObject, handles);% --- Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)% hObject handle to pushbutton17 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global locaval;a = get(handles.pushbutton17,'String');locaval=strcat(locaval,a);set(handles.edit1,'String',locaval);global gloval2gloval2=locaval;guidata(hObject, handles);% --- Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)% hObject handle to pushbutton18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global flagnumglobal gloval1global gloval2global locavallocaval=' ';gloval1=str2num(gloval1);gloval2=str2num(gloval2);case1=gloval1/gloval2;case2=gloval1*gloval2;case3=gloval1-gloval2;case4=gloval1+gloval2;case1=num2str(case1);case2=num2str(case2);case3=num2str(case3);case4=num2str(case4);switch flagnum;case 1set(handles.edit1,'String',case1);case 2set(handles.edit1,'String',case2);case 3set(handles.edit1,'String',case3);case 4set(handles.edit1,'String',case4);endguidata(hObject,handles)% --- Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)% hObject handle to pushbutton19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) edit1String = get(handles.edit1,'String');if(strcmp(edit1String,'0.')==1)set(handles.edit1,'String','0.') ;elsess=char(edit1String);l=length(edit1String);edit1String=ss(1:l-1);set(handles.edit1,'String',edit1String)endguidata(hObject,handles)% --- Executes on button press in pushbutton20.function pushbutton20_Callback(hObject, eventdata, handles)% hObject handle to pushbutton20 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global locavallocaval=' ';set(handles.edit1,'String','0');guidata(hObject,handles)function edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (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 COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end五.结果展示。
GUI设计的简易计算器附程序
电子信息工程系实验报告课程名称:MATLAB应用Array实验项目名称:GUI计算器设计实验时间:2012-11-22班级:测控081 姓名:学号:810707132实验目的:1.熟悉MATLAB的菜单设计方法2. 熟悉MATLAB的主要控件使用方法3. 熟悉MATLAB的GUI设计流程4.运用MATLAB的GUI设计一个简单的计算器实验环境:MATLAB7.8实验内容:function varargout = jisuanqi1(varargin)% JISUANQI1 M-file for jisuanqi1.fig% JISUANQI1, by itself, creates a new JISUANQI1 or raises the existing% singleton*.%% H = JISUANQI1 returns the handle to a new JISUANQI1 or the handle to% the existing singleton*.%% JISUANQI1('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in JISUANQI1.M with the given input arguments. %% JISUANQI1('Property','Value',...) creates a new JISUANQI1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before jisuanqi1_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application % stop. All inputs are passed to jisuanqi1_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 response to help jisuanqi1% Last Modified by GUIDE v2.5 05-Dec-2010 22:24:59% Begin initialization code - DO NOT EDITgui_Singleton = 1;'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @jisuanqi1_OpeningFcn, ...'gui_OutputFcn', @jisuanqi1_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 jisuanqi1 is made visible.function jisuanqi1_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 jisuanqi1 (see VARARGIN)% 以下是本实验初始化部分程序的代码:global c p t c1 f;f=0;t=0;p=2;c1=num2str(0);c= '0.';set(handles.edit1,'String',c);guidata(hObject, handles);% Choose default command line output for jisuanqi1handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes jisuanqi1 wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = jisuanqi1_OutputFcn(hObject, eventdata, handles)% 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 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 structure with handles and user data (see GUIDATA)% 以下是本实验数字‘8’的程序代码:global t f c;if f=='=';c='0';c=8+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=8+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'8');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;end% --- Executes on button 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)% 以下是本实验数字‘5’的程序代码:global t f c;if f=='=';c='0';c=5+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);elseif t==0;c=5+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'5');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;end% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘2’的程序代码:global t f c;if f=='=';c='0';c=2+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=2+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'2');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;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 % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘+/-’的程序代码:global c t p;c=strcat('-',c);set(handles.edit1,'String',c);guidata(hObject, handles);p=p+1;elsec=strrep(c,'-','');set(handles.edit1,'String',c);guidata(hObject, handles);p=p+1;end% --- Executes on 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)% 以下是本实验‘.’的程序代码:global c t;t=1;c=strcat(c,'.');set(handles.edit1,'String',c);guidata(hObject, handles);% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘3’的程序代码:global t f c;if f=='=';c='0';c=3+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=3+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'3');set(handles.edit1,'String',c);t=t+1;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 % handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘6’的程序代码:global t f c;if f=='=';c='0';c=6+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=6+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'6');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;end% --- Executes 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)% 以下是本实验数字‘9’的程序代码:global t f c;if f=='=';c='0';c=9+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=9+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);elsec=strcat(c,'9');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;end% --- Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject 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)% 以下是本实验‘+’的程序代码:global c c1 f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='+';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject, handles);c=num2str(0);c1=num2str(0);f='=';elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='+';elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='+';elsec1=str2num(c)+str2num(c1);c1=num2str(c1);guidata(hObject, handles);c=num2str(0);f='+';endt=0;% --- 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 of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘-’的程序代码:global c c1 f t;if (c1==num2str(0)&f==0)|(c1==num2str(0)&f=='=')c1=str2num(c)-str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='-';elseif f=='+';c1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='-';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject, handles);c=num2str(0);c1=num2str(0);f='=';elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='-';elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);c=num2str(0);f='-';elsec1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='-';endt=0;% --- 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 with handles and user data (see GUIDATA)% 以下是本实验‘*’的程序代码:global c c1 f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='*';elseif f=='+';c1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='*';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject, handles);c=num2str(0);c1=num2str(0);f='=';elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);f='*';elseif (c1==num2str(0)&f==0)|(c1==num2str(0)&f=='=');c1=str2num(c)*(str2num(c1)+1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='*';elsec1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='*';endt=0;% --- Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, eventdata, 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)% 以下是本实验‘/’的程序代码:global c c1 f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='/';elseif f=='+';c1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='/';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject, handles);c=num2str(0);c1=num2str(0);elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='/';elseif (c1==num2str(0)&f==0)|(c1==num2str(0)&f=='=');c1=str2num(c)/(str2num(c1)+1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='/';elsec1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);f='/';endt=0;% --- Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, eventdata, handles)% hObject handle to pushbutton15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘0’的程序代码:global t f c;if f=='=';c='0';c=0+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=0+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'0');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;end% --- Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘1’的程序代码:global t f c;if f=='=';c='0';c=1+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=1+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'1');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;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 a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘4’的程序代码:global t f c;if f=='=';c='0';c=4+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=4+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'4');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;endfunction edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version 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 edit1_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 COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end% --- Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)% hObject handle to pushbutton18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 以下是本实验数字‘7’的程序代码:global t f c;if f=='=';c='0';c=7+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elseif t==0;c=7+str2num(c)*10;c= num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);elsec=strcat(c,'7');set(handles.edit1,'String',c);guidata(hObject, handles);t=t+1;end% --- Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)% hObject handle to pushbutton19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘CE’的程序代码:global c c1 f;f=0;c1=num2str(0);c=0;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject, handles);c=num2str(0);t=0;% --- Executes on button press in pushbutton20.function pushbutton20_Callback(hObject, eventdata, handles)% hObject handle to pushbutton20 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘=’的程序代码:global c c1 f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject, handles);c=num2str(0);f=0;elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);elsec1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);endt=0;f='=';c=c1;c1=num2str(0);% --- Executes on button press in pushbutton21.function pushbutton21_Callback(hObject, eventdata, handles)% hObject handle to pushbutton21 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton22.function pushbutton22_Callback(hObject, eventdata, handles)% hObject handle to pushbutton22 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘sqrt’的程序代码:global c c1 f t;c1=sqrt(str2num(c))c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);c=c1;c1=num2str(0);t=0;f='=';% --- Executes on button press in pushbutton23.function pushbutton23_Callback(hObject, eventdata, handles)% hObject handle to pushbutton23 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘π’的程序代码:global c;c=num2str(pi);set(handles.edit1,'String','¦Ð');guidata(hObject, handles);% --- Executes on button press in pushbutton24.function pushbutton24_Callback(hObject, eventdata, handles)% hObject handle to pushbutton24 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘Backspace’的程序代码:global c t;if t==0;c=floor(str2num(c)/10);c=num2str(c);elseif t==2;c=floor(str2num(c));c=num2str(c);c=strcat(c,'.');t=t-1;elseif t==1;c=floor(str2num(c));c=num2str(c);t=t-1;elsec=(floor(str2num(c)*10^(t-1)/10))*10^(-t+2);c=num2str(c);t=t-1;endset(handles.edit1,'String',c);guidata(hObject, handles);% --- Executes on button press in pushbutton25.function pushbutton25_Callback(hObject, eventdata, handles)% hObject handle to pushbutton25 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘1/x’的程序代码:global c c1 f t;if c==num2str(0)|c1==num2str(0);c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject, handles);elsec1=1/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);endc=num2str(0);c=c1;c1=num2str(0);t=0;f='=';% --- Executes on button press in pushbutton26.function pushbutton26_Callback(hObject, eventdata, handles)% hObject handle to pushbutton26 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% 以下是本实验‘exp’的程序代码:global c c1 f t;c1=exp(str2num(c))c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject, handles);c=num2str(0);c=c1;c1=num2str(0);t=0;f='=';实验结果及分析:实验心得:这次实验做的是电脑附件里的计算器,通过该实验我更熟悉掌握了MA TLAB中GUI各控件使用方法及应用,最后并利用GUI设计出了计算器,这些让我对GUI页面中的各控件的功能有了进一步的了解。
matlab gui实例
matlab gui实例MATLAB GUI实例MATLAB GUI是一种基于图形用户界面的交互式工具,它可以帮助用户快速创建自己的图形界面,并且可以通过简单的拖放操作来实现各种功能。
在本文中,我们将介绍一个简单的MATLAB GUI实例,以帮助初学者更好地理解和掌握这一工具。
首先,我们需要创建一个新的MATLAB GUI。
在MATLAB主界面中,选择“新建”->“GUI”->“App Designer”,然后选择“Blank App”模板。
接下来,我们需要添加一些基本的组件,例如按钮、文本框和列表框。
这些组件可以通过拖放操作从左侧的“组件”面板中添加到GUI窗口中。
在本例中,我们将创建一个简单的计算器应用程序,用户可以通过输入两个数字和选择一个操作符来计算结果。
因此,我们需要添加两个文本框用于输入数字,一个列表框用于选择操作符,一个按钮用于触发计算操作,并且一个文本框用于显示结果。
这些组件可以通过以下代码添加到GUI窗口中:```matlabclassdef Calculator < matlab.apps.AppBase% Properties that correspond to app componentsproperties (Access = public)UIFigure matlab.ui.FigureNumber1EditField matlab.ui.control.NumericEditField Number2EditField matlab.ui.control.NumericEditField OperatorListBox matlab.ui.control.ListBoxCalculateButton matlab.ui.control.ButtonResultEditField matlab.ui.control.NumericEditField end% Callbacks that handle component eventsmethods (Access = private)% Button pushed function: CalculateButtonfunction CalculateButtonPushed(app, event)% Get the input valuesnum1 = app.Number1EditField.Value;num2 = app.Number2EditField.Value;op = app.OperatorListBox.Value;% Calculate the resultswitch opcase '+'result = num1 + num2;case '-'result = num1 - num2;case '*'result = num1 * num2;case '/'result = num1 / num2;end% Display the resultapp.ResultEditField.Value = result; endend% App initialization and constructionmethods (Access = private)% Create UIFigure and componentsfunction createComponents(app)% Create UIFigure and set propertiesapp.UIFigure = uifigure('Name', 'Calculator');app.UIFigure.Position = [100 100 640 480];% Create Number1EditFieldapp.Number1EditField = uieditfield(app.UIFigure,'numeric');app.Number1EditField.Position = [50 400 100 22];% Create Number2EditFieldapp.Number2EditField = uieditfield(app.UIFigure,'numeric');app.Number2EditField.Position = [200 400 100 22];% Create OperatorListBoxapp.OperatorListBox = uilistbox(app.UIFigure);app.OperatorListBox.Items = {'+', '-', '*', '/'};app.OperatorListBox.Position = [350 400 100 80];app.OperatorListBox.Value = '+';% Create CalculateButtonapp.CalculateButton = uibutton(app.UIFigure, 'push'); app.CalculateButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateButtonPushed, true);app.CalculateButton.Position = [500 400 100 22];app.CalculateButton.Text = 'Calculate';% Create ResultEditFieldapp.ResultEditField = uieditfield(app.UIFigure, 'numeric'); app.ResultEditField.Position = [50 300 100 22];app.ResultEditField.Value = 0;endend% App creation and deletionmethods (Access = public)% Construct appfunction app = Calculator% Create UIFigure and componentscreateComponents(app);% Show the figure after all components are createdapp.UIFigure.Visible = 'on';endendend```在上面的代码中,我们定义了一个名为“Calculator”的类,它继承自“matlab.apps.AppBase”类。
matlab中加法的运算符
matlab中加法的运算符在MATLAB中,加法运算符用于将两个数值相加或将两个向量/矩阵的对应元素相加。
MATLAB支持多种形式的加法运算符,包括元素级加法、矩阵加法和字符串拼接。
1. 元素级加法:元素级加法是指对两个具有相同维度的向量/矩阵进行对应元素的相加运算。
在MATLAB中,可以使用"+"运算符实现元素级加法。
示例1:对两个向量进行元素级加法```matlaba = [1, 2, 3];b = [4, 5, 6];result = a + b;disp(result);```运行以上代码,将输出结果为:```5 7 9```示例2:对两个矩阵进行元素级加法```matlabA = [1, 2, 3; 4, 5, 6];B = [7, 8, 9; 10, 11, 12];result = A + B;disp(result);```运行以上代码,将输出结果为:```8 10 1214 16 18```2. 矩阵加法:矩阵加法是指对两个具有相同行数和列数的矩阵进行相加运算。
在MATLAB中,可以使用"+"运算符实现矩阵加法。
示例3:对两个矩阵进行矩阵加法```matlabA = [1, 2, 3; 4, 5, 6];B = [7, 8, 9; 10, 11, 12];result = A + B;disp(result);```运行以上代码,将输出结果为:```8 10 1214 16 18```需要注意的是,进行矩阵加法时,两个矩阵必须具有相同的行数和列数。
3. 字符串拼接:除了数值之间的加法运算外,在MATLAB中还可以使用加法运算符进行字符串的拼接。
当字符串与其他类型的变量(如数值、向量、矩阵等)相加时,MATLAB会将其转换为字符串,并将其拼接起来。
示例4:字符串拼接```matlabstr1 = 'Hello, ';str2 = 'MATLAB!';result = str1 + str2;disp(result);```运行以上代码,将输出结果为:```Hello, MATLAB!```需要注意的是,进行字符串拼接时,"+"运算符必须至少包含一个字符串类型的变量。
用MATLAB做一个计算器包括加减乘除平方清空等功能
广西科技大学MATLAB课程设计说明书课题:设计简易计算器开发环境:MATLAB GUIDE作者:系别:专业:时间:实验目的:1、熟悉MATLAB的主要控件使用方法。
2、熟悉MATLAB的GUI设计流程。
实验环境:编程软件:MATLAB7.0实验内容与结果:使用MATLAB的GUI接口设计一个简单的计算器。
效果图:一、布局GUI。
1.打开Matlab,输入Guide 回车或者在工具栏上点击图标出现Guide 窗口:2.然后双击“Blank GUI(Default)”出现GUI窗口3.添加按钮4.根据按钮的作用及视觉效果做一定的修改把按钮的字符串大小、颜色进行设置,对按钮的位置进行排布,尽量使按钮集中在静态文本框下面。
最终设置的静态文本框为白色,其他按钮均为分红色。
5.保存、添加功能函数把做好的按钮及静态文本框保存后自动弹出Editor的M文本,对然后对相应的pushbutton添加功能函数。
以下是相应按钮的功能函数。
(1)数字按键编写。
在function pushbutton1_Callback(hObject, eventdata, handles)下输入:textString = get(handles.text1,'String');textString =strcat(textString,'0');set(handles.text1,'String',textString)这是使用句柄handles指向对象text1,并以字符串形式来存储数据文本框text1的内容,并存储数个“0”,然后由set(handles.text1,'String','textString'在text1中输出。
同理,分别在function pushbutton2~10_Callback(hObject, eventdata, handles)下给1~9数字按键下编写此类程序。
matlabGUI计算器
计算器一、实习任务利用MATLAB里面的函数和GUI用户设计工具箱,制作简易计算器,实现简单的计算任务。
二、实习内容1、布局设计2、程序设计(1)数字按键textString = get(handles.text1,'String');textString = strcat(textString,'0');set(handles.text1,'string',textString)(2)符号按键textString = get(handles.text1,'String'); textString = strcat(textString,'*');set(handles.text1,'string',textString)(3)清零按键set(handles.text1,'string','')(4)返回按键textString = get(handles.text1,'String');set(handles.text1,'String','');ss=char(textString);n=length(textString);textString = ss(1:n-1);set(handles.text1,'string',textString)(5)函数按键textString = handles.text1;textString =sin(str2num(get(handles.text1,'String'))*pi/180); set(handles.text1,'string',num2str(textString)) ; (get(handles.text1,'String'))*pi/1803、效果图三、遇到的问题及解决方法1、遇到的问题在这次MATLAB简易计算器设计中,最大的问题就是不知道如何编写程序,其次就是在Command里面实现了,但在GUI用户界面不知道如何操作编写。
用MATLAB GUI做计算器,
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
handles.current_str=strcat(handles.current_str,'4');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);
% --- Executes on button press in pushbutton5.
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = calculator_OutputFcn(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit1_Callback(hObject, eventdata, handles)
matlab gui实例
matlab gui实例MATLAB GUI实例MATLAB是一种非常流行的数学软件,它可以用于各种数学计算和数据分析。
MATLAB GUI是一种图形用户界面,它可以让用户通过图形界面来操作MATLAB程序。
在本文中,我们将介绍一个MATLAB GUI实例,以帮助读者更好地了解MATLAB GUI的使用。
我们需要创建一个新的MATLAB GUI。
在MATLAB中,可以通过选择“新建”菜单来创建一个新的GUI。
然后,我们需要添加一些控件,例如按钮、文本框和列表框。
这些控件可以通过拖放方式添加到GUI中。
在本例中,我们将添加一个按钮和一个文本框。
接下来,我们需要编写一些MATLAB代码来实现GUI的功能。
在本例中,我们将编写一个简单的程序,该程序将读取文本框中的文本,并将其显示在命令窗口中。
我们可以使用MATLAB的“get”函数来获取文本框中的文本,并使用“disp”函数将其显示在命令窗口中。
我们需要将GUI保存为一个MATLAB文件。
这个文件可以被其他人使用,他们可以通过运行这个文件来打开GUI并使用它。
在本例中,我们将保存GUI为“mygui.m”文件。
现在,我们可以运行这个GUI并测试它的功能。
当我们单击按钮时,GUI将读取文本框中的文本,并将其显示在命令窗口中。
这个程序非常简单,但它演示了如何使用MATLAB GUI来创建一个简单的程序。
总结MATLAB GUI是一个非常有用的工具,它可以让用户通过图形界面来操作MATLAB程序。
在本文中,我们介绍了一个MATLAB GUI实例,以帮助读者更好地了解MATLAB GUI的使用。
通过这个实例,读者可以学习如何创建一个简单的GUI,并使用MATLAB代码来实现它的功能。
我们希望这篇文章能够帮助读者更好地了解MATLAB GUI,并在实际应用中发挥作用。
matlab循环加法
matlab循环加法在MATLAB中,可以使用循环来实现加法运算。
下面我将从多个角度来解释如何在MATLAB中使用循环进行加法运算。
首先,我们可以使用for循环来实现加法运算。
假设我们有两个向量a和b,我们想要计算它们的和,可以使用以下代码:matlab.a = [1, 2, 3, 4, 5];b = [6, 7, 8, 9, 10];result = zeros(size(a));for i = 1:length(a)。
result(i) = a(i) + b(i);end.disp(result)。
在这个例子中,我们首先创建了两个向量a和b,然后创建了一个名为result的与a相同大小的零向量。
接下来,我们使用for循环遍历a和b的每个元素,并将它们相加并存储在result向量中。
最后,我们使用disp函数显示结果。
除了使用for循环,我们还可以使用MATLAB的向量化操作来实现加法运算。
向量化操作可以提高代码的执行效率。
例如,我们可以直接将两个向量相加,而不需要使用循环:matlab.a = [1, 2, 3, 4, 5];b = [6, 7, 8, 9, 10];result = a + b;disp(result)。
在这个例子中,我们直接使用a + b来计算两个向量的和,MATLAB会自动执行元素级的加法操作,无需显式地使用循环。
另外,MATLAB还提供了一些内置的函数来执行向量和矩阵的加法运算,例如sum函数和plus函数。
这些函数可以简化加法运算的实现,并且在处理大型数据集时可以提高计算效率。
总之,在MATLAB中可以使用循环、向量化操作以及内置函数来实现加法运算。
选择合适的方法取决于具体的应用场景和个人偏好。
希望这些解释能够帮助你更好地理解在MATLAB中实现加法运算的方法。
matlab加法运算符
matlab加法运算符
在MATLAB 中,加法运算符使用加号+ 来表示。
您可以使用它来对两个数字、向量、矩阵或数组进行加法运算。
以下是一些示例:
1. 数字加法:
matlab复制代码:
result = 3 + 4; % 结果是7
2. 向量加法:
当您有两个相同大小的向量时,可以使用+ 运算符对它们进行逐元素的加法。
matlab复制代码:
A = [1, 2, 3];
B = [4, 5, 6];
C = A + B; % 结果是[5, 7, 9]
3. 矩阵加法:
与向量一样,当您有两个相同大小的矩阵时,可以使用+ 运算符对它们进行逐元素的加法。
matlab复制代码:
A = [1, 2; 3, 4];
B = [5, 6; 7, 8];
C = A + B; % 结果是[6, 8; 10, 12]
4. 标量与数组、向量或矩阵的加法:
当您有一个标量和一个数组(或向量、矩阵)时,标量会被加到数组的每个元素上。
matlab复制代码:
A = [1, 2, 3];
B = 2;
C = A + B; % 结果是[3, 4, 5]
请注意,当使用+ 运算符时,确保操作数的维度是兼容的。
如果维度不匹配,MATLAB 会报错。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Matlab GUI编程实现加法器
一.首先我们新建一个GUI文件:File/New/GUI,选择Blank GUI(Default),如下图所示
二.进入GUI开发环境以后添加两个编辑文本框,6个静态文本框和一个按钮,布置如下图所示:
布置好各控件以后,我们就可以来为这些控件编写程序来实现两数相加的功能了。
三.我们先为数据1文本框添加代码;
点击上图所示红色方框,选择edit1_Callback,或者是在数据1文本框出右键选择View Callbacks–>Callback,光标便立刻移到下面这段代码的位置:
function edit1_Callback(hObject,eventdata,handles)
%hObject handle to edit1(see GCBO)
%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)
%Hints:get(hObject,'String')returns contents of edit1as text %str2double(get(hObject,'String'))returns contents of edit1 as a double
然后在上面这段代码的下面插入如下代码:
input=str2num(get(hObject,'String'));
if(isempty(input))
set(hObject,'String','0');
end
guidata(hObject,handles);
这段代码使得输入被严格限制,我们不能试图输入一个非数字。
四.为edit2_Callback添加同样一段代码。
五.现在我们为计算按钮添加代码来实现把数据1和数据2相加的目的。
用上面三的同样的方法在m文件中找到pushbutton1_Callback代码段如下:
function pushbutton1_Callback(hObject,eventdata,handles)
%hObject handle to pushbutton1(see GCBO)
%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)
%a and b are variables of strings type,and needs to be converted 在上面这段代码后添加以下代码:
a=get(handles.edit1,'String');
b=get(handles.edit2,'String');
total=str2num(a)+str2num(b);
%the result needs to be converted back into string type to display it
c=num2str(total);
set(handles.text3,'String',c);
guidata(hObject,handles);
下面我们来对上面这段程序分析一下;
a=get(handles.edit1,'String');b=get(handles.edit2,'String');
上面这行代码把用户输入的数据存入到变量a,变量b中;%a,b是字符型变量,在计算两者相加之前需把他们转换为数字型。
total=str2num(a)+str2num(b);
这段代码实现两数相加c=num2str(total);
set(handles.text3,'String',c);
guidata(hObject,handles);
以上两行代码分别用来更新计算结果文本框和图形对象句柄,一般Callback回调函数都以guidata(hObject,handles)结束以更新数据。
程序运行如下:。