matlab简易计算器设计步骤与回调函数设计说明Word格式文档下载.docx
《matlab简易计算器设计步骤与回调函数设计说明Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《matlab简易计算器设计步骤与回调函数设计说明Word格式文档下载.docx(21页珍藏版)》请在冰豆网上搜索。
,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
pushbutton
Pushbutton1
1
16
points
bold
on
0.498
Pushbutton2
2
Pushbutton3
3
Pushbutton4
4
Pushbutton5
5
Pushbutton6
6
Pushbutton7
7
Pushbutton8
8
Pushbutton9
9
pushbutton10
pushbutton11
+
43
pushbutton12
-
pushbutton13
×
pushbutton14
÷
pushbutton15
=
pushbutton16
.
pushbutton17
Exit
pushbutton18
Delete
pushbutton19
Clc
Pushbutton20
(
Pushbutton21
)
text
text1
制作:
***
0.831
0.816
0.784
text2
Input
text3
Output
text4
算术计算器
20
0.749
edit
edit1
空白字符串
10
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,'
);
%字符串合并函数strcat()将按键"
0"
与numbers的值合并,将合并后的字符串返回到输入文本框edit1的string属性;
set(handles.edit1,'
strcat(numbers,'
0'
));
%同理编写其余数字键、小数点键、小括号键、运算符号键;
(2)数字键1的回调函数:
%---Executesonbuttonpressinpushbutton7.
functionpushbutton1_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton7(seeGCBO)
%数字键1的回调函数:
1'
(3)数字键2的回调函数:
functionpushbutton2_Callback(hObject,eventdata,handles)
%数字键2的回调函数:
2'
(4)数字键3的回调函数:
%---Executesonbuttonpressinpushbutton10.
functionpushbutton3_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton10(seeGCBO)
%数字键3的回调函数:
3'
(5)数字键4的回调函数:
%---Executesonbuttonpressinpushbutton9.
functionpushbutton4_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton9(seeGCBO)
%数字键4的回调函数:
4'
(6)数字键5的回调函数:
functionpushbutton5_Callback(hObject,eventdata,handles)
%数字键5的回调函数:
5'
(7)数字键6的回调函数:
%---Executesonbuttonpressinpushbutton6.
functionpushbutton6_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton6(seeGCBO)
%数字键6的回调函数:
6'
(8)数字键7的回调函数:
%---Executesonbuttonpressinpushbutton5.
functionpushbutton7_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton5(seeGCBO)
%eventdatareserved-tobedefinedinafutureversio