matlab简易计算器设计步骤与回调函数设计说明Word文档下载推荐.docx
《matlab简易计算器设计步骤与回调函数设计说明Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《matlab简易计算器设计步骤与回调函数设计说明Word文档下载推荐.docx(23页珍藏版)》请在冰点文库上搜索。
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)
%数字键7的回调函数:
7'
(9)数字键8的回调函数:
%---Executesonbuttonpressinpushbutton8.
functionpushbutton8_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton8(seeGCBO)
%数字键8的回调函数:
8'
(10)数字键9的回调函数:
%---Executesonbuttonpressinpushbutton4.
functionpushbutton9_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton4(seeGCBO)
%数字键9的回调函数:
9'
(11)小数点“.”键的回调函数:
%---Executesonbuttonpressinpushbutton17.
functionpushbutton16_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton17(seeGCBO)
%小数点的回调函数;
point=get(handles.edit1,'
strcat(point,'
.'
(12)加号“+”键的回调函数:
functionpushbutton11_Callback(hObject,eventdata,handles)
%加号“+”键的回调函数;
signs=get(handles.edit1,'
strcat(signs,'
+'
(13)减号“-”键的回调函数:
functionpushbutton12_Callback(hObject,eventdata,handles)
%减号“-”键的回调函数;
-'
(14)乘号“×
”键的回调函数:
functionpushbutton13_Callback(hObject,eventdata,handles)
%乘号“×
”键的回调函数;
*'
(15)除号“÷
functionpushbutton14_Callback(hObject,eventdata,handles)
%除号“÷
/'
(16)左括号“(”键的回调函数:
%---Executesonbuttonpressinpushbutton21.
functionpushbutton21_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton21(seeGCBO)
%左括号“(”键的回调函数;
('
(17)右括号“)”键的回调函数:
%---Executesonbuttonpressinpushbutton20.
functionpushbutton20_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton20(seeGCBO)
%右括号“)”键的回调函数;
)'
(18)等号“=”号键的回调函数:
%---Executesonbuttonpressinpushbutton15.
functionpushbutton15_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton15(seeGCBO)
%等号“=”号键的回调函数;
%get函数获取输入文本框edit1的string属性,并赋值与x;
x=get(handles.edit1,'
%利用执行字符串命令eval()计算用户输入的表达式,得到的结果为char型;
y1=eval(x);
%利用字符串输出格式控制函数sprintf()将字符型常量精确到小数点后十位;
y=sprintf('
y1);
%利用属性设置函数set()将字符型结果返回到输出文本框edit2的string属性;
set(handles.edit2,'
y);
(19)CLC键的回调函数:
%---Executesonbuttonpressinpushbutton19.
functionpushbutton19_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton19(seeGCBO)
%CLC键的回调函数;
%清空输入文本框edit1的string属性;
String'
'
'
%清空输出文本框edit2的string属性;
(20)Delete键的回调函数:
%---Executesonbuttonpressinpushbutton18.
functionpushbutton18_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton18(seeGCBO)
%