matlab简易计算器设计步骤与回调函数设计.docx

上传人:b****1 文档编号:2257660 上传时间:2023-05-03 格式:DOCX 页数:23 大小:716.22KB
下载 相关 举报
matlab简易计算器设计步骤与回调函数设计.docx_第1页
第1页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第2页
第2页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第3页
第3页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第4页
第4页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第5页
第5页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第6页
第6页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第7页
第7页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第8页
第8页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第9页
第9页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第10页
第10页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第11页
第11页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第12页
第12页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第13页
第13页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第14页
第14页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第15页
第15页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第16页
第16页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第17页
第17页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第18页
第18页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第19页
第19页 / 共23页
matlab简易计算器设计步骤与回调函数设计.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

matlab简易计算器设计步骤与回调函数设计.docx

《matlab简易计算器设计步骤与回调函数设计.docx》由会员分享,可在线阅读,更多相关《matlab简易计算器设计步骤与回调函数设计.docx(23页珍藏版)》请在冰点文库上搜索。

matlab简易计算器设计步骤与回调函数设计.docx

matlab简易计算器设计步骤与回调函数设计

简易算术计算器的设计

一、算术计算器的功能:

能进行简单的加、减、乘、除法运算,输入文本框显示为常量多项式,输出文本框显示为精确到小数点后十位的数值。

计算器包含十个数字键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、运行matlab7.13版,进入主界面。

 

2、点击工具栏上的GUIDE图标进入GUI开发环境。

 

3、创建控件:

PushButton包括数字0~9、运算符“+-×÷”、功能键等十九个,输入和动态静态文本框EditText,显示文字的静态文本框StaticText四个等。

4、对控件单击右键弹出菜单,选择PropertyInspector,设置控件属性。

 

 

 

 

 

 

 

控件属性表

控件Style类型

Tag

String

FontSize

FontUnits

FontWeight

Visible

BackgroundColor

ForegroundColor

red

green

blue

red

green

blue

pushbutton

Pushbutton1

1

16

points

bold

on

0

0.498

0

1

1

0

Pushbutton2

2

Pushbutton3

3

Pushbutton4

4

Pushbutton5

5

Pushbutton6

6

Pushbutton7

7

Pushbutton8

8

Pushbutton9

9

pushbutton10

0

pushbutton11

43

pushbutton12

pushbutton13

×

pushbutton14

÷

pushbutton15

=

16

pushbutton16

.

pushbutton17

Exit

pushbutton18

Delete

pushbutton19

Clc

Pushbutton20

Pushbutton21

text

text1

制作:

***

16

points

bold

on

0.831

0.816

0.784

0

0

1

text2

Input

text3

Output

text4

算术计算器

20

0.749

0

0.749

edit

edit1

空白字符串

10

points

on

1

1

1

0

0

0

edit2

空白字符串

 

5、选择工具栏上的AlignObjects按键,调整控件布局。

 

6、选择工具栏上的TabOderEditor按键,通过

设置各控件的Tab顺序。

 

7、设计菜单:

在GUI开发环境下,选择工具栏上的

进入菜单编辑器,分别选择

创建主菜单和子菜单。

8、编写回调函数。

(1)数字键0的回调函数:

%---Executesonbuttonpressinpushbutton3.

functionpushbutton10_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton3(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键0的回调函数:

%get函数获取输入文本框edit1的string属性,赋值给numbers,数值类型为char;

numbers=get(handles.edit1,'string');

%字符串合并函数strcat()将按键"0"与numbers的值合并,将合并后的字符串返回到输入文本框edit1的string属性;

set(handles.edit1,'string',strcat(numbers,'0'));

%同理编写其余数字键、小数点键、小括号键、运算符号键;

(2)数字键1的回调函数:

%---Executesonbuttonpressinpushbutton7.

functionpushbutton1_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton7(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键1的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'1'));

 

(3)数字键2的回调函数:

%---Executesonbuttonpressinpushbutton7.

functionpushbutton2_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton7(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键2的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'2'));

 

(4)数字键3的回调函数:

%---Executesonbuttonpressinpushbutton10.

functionpushbutton3_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton10(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键3的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'3'));

 

(5)数字键4的回调函数:

%---Executesonbuttonpressinpushbutton9.

functionpushbutton4_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton9(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键4的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'4'));

 

(6)数字键5的回调函数:

%---Executesonbuttonpressinpushbutton7.

functionpushbutton5_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton7(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键5的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'5'));

 

(7)数字键6的回调函数:

%---Executesonbuttonpressinpushbutton6.

functionpushbutton6_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton6(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键6的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'6'));

 

(8)数字键7的回调函数:

%---Executesonbuttonpressinpushbutton5.

functionpushbutton7_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton5(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键7的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'7'));

 

(9)数字键8的回调函数:

%---Executesonbuttonpressinpushbutton8.

functionpushbutton8_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton8(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键8的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'8'));

 

(10)数字键9的回调函数:

%---Executesonbuttonpressinpushbutton4.

functionpushbutton9_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton4(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%数字键9的回调函数:

numbers=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(numbers,'9'));

 

(11)小数点“.”键的回调函数:

%---Executesonbuttonpressinpushbutton17.

functionpushbutton16_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton17(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%小数点的回调函数;

point=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(point,'.'));

 

(12)加号“+”键的回调函数:

%---Executesonbuttonpressinpushbutton10.

functionpushbutton11_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton10(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%加号“+”键的回调函数;

signs=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(signs,'+'));

 

(13)减号“-”键的回调函数:

%---Executesonbuttonpressinpushbutton9.

functionpushbutton12_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton9(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%减号“-”键的回调函数;

signs=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(signs,'-'));

 

(14)乘号“×”键的回调函数:

%---Executesonbuttonpressinpushbutton7.

functionpushbutton13_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton7(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%乘号“×”键的回调函数;

signs=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(signs,'*'));

 

(15)除号“÷”键的回调函数:

%---Executesonbuttonpressinpushbutton8.

functionpushbutton14_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton8(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%除号“÷”键的回调函数;

signs=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(signs,'/'));

(16)左括号“(”键的回调函数:

%---Executesonbuttonpressinpushbutton21.

functionpushbutton21_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton21(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%左括号“(”键的回调函数;

signs=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(signs,'('));

 

(17)右括号“)”键的回调函数:

%---Executesonbuttonpressinpushbutton20.

functionpushbutton20_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton20(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%右括号“)”键的回调函数;

signs=get(handles.edit1,'string');

set(handles.edit1,'string',strcat(signs,')'));

(18)等号“=”号键的回调函数:

%---Executesonbuttonpressinpushbutton15.

functionpushbutton15_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton15(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%等号“=”号键的回调函数;

%get函数获取输入文本框edit1的string属性,并赋值与x;

x=get(handles.edit1,'string');

%利用执行字符串命令eval()计算用户输入的表达式,得到的结果为char型;

y1=eval(x);

%利用字符串输出格式控制函数sprintf()将字符型常量精确到小数点后十位;

y=sprintf('%.10f',y1);

%利用属性设置函数set()将字符型结果返回到输出文本框edit2的string属性;

set(handles.edit2,'string',y);

(19)CLC键的回调函数:

%---Executesonbuttonpressinpushbutton19.

functionpushbutton19_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton19(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%CLC键的回调函数;

%清空输入文本框edit1的string属性;

set(handles.edit1,'String','');

%清空输出文本框edit2的string属性;

set(handles.edit2,'String','0');

(20)Delete键的回调函数:

%---Executesonbuttonpressinpushbutton18.

functionpushbutton18_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton18(seeGCBO)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2