按键0~9的功能函数:(这里只列举按键0的功能函数,其他9个按键只需将函数名 pushbutton1_Callback和‘0’依次换成各自的函数名和相应的值即可)
function pushbutton1_Callback(hObject, eventdata, handles)
textString = get(handles.text1,'String');
textString =strcat(textString,'0');
set(handles.text1,'String',textString);
符号键+,-,*,.,/,的功能函数:(这里只列举按键+的功能函数,其他4个按键只需将函数名pushbutton11_Callback 和‘+’依次换成各自的函数名和相应的值即可)
function pushbutton11_Callback(hObject, eventdata, handles)
textString = get(handles.text1,'String');
textString =strcat(textString,'+');%strcat的作用是将两个字符串连接起来,就是在已输入的存储数据textString后添加“+”进行运算。
set(handles.text1,'String',textString)
平方函数:^2
function pushbutton17_Callback(hObject, eventdata, handles)
textString = get(handles.text1,'String');
textString =strcat(textString,'^2');
set(handles.text1,'String',textString)
back功能函数:
function pushbutton18_Callback(hObject, eventdata, handles)
textString = get(handles.text1,'String');
set(handles.text1,'String','') ;
ss=char(textString);
n=length(textString);
textString=ss(1:w-1);%将w个字符串转成w-1个,即删除了末位字符
set(handles.text1,'String',textString)
清零功能函数:
function pushbutton19_Callback(hObject, eventdata, handles)
set(handles.text1,'String','') %把静态文本框的字符清空,返回一个空格
"="功能函数:
function pushbutton16_Callback(hObject, eventdata, handles)
textString = get(handles.text1,'String');
ans =eval(textString);%eval的作用是将符号表达式转换成数值表达式
set(handles.text1,'String',ans);%将运算结果ans显示
退出功能函数:
function pushbutton20_Callback(hObject, eventdata, handles)
close(gcf);%关闭计算器