1/15目录计算器的效果图...........................................................................错误!未定义书签。一、GUI设计界面:...................................................................................................31.打开GUI....................................................................................................................32.添加按钮.....................................................................................................................33.根据按钮的作用及视觉效果做一定的修改:.........................................................44.保存、添加功能函数.................................................................................................4(1)数字键编写.....................................................................................................................4(2)符号键的编写.................................................................................................................4(3)运算符“=”的编写......................................................................................................5(4)按键“←back”的编写...................................................................................................5(5)按键“清空”的编写.....................................................................................................5(6)按键“退出”的编写.....................................................................................................5(7)按键“二进制数转十进制数”的编写.........................................................................5(8)按键“十进制数转二进制数”的编写.........................................................................5二、计算器的使用........................................................................................................6除法运算(÷)........................................................................................................................6平方运算(^2).......................................................................................................................6函数cos(∏/3)的计算.....................................................................................................7函数arctan(∏/3)的计算.................................................................................................7以2为底的对数的计算(log2)...........................................................................................8十进制数转二进制数的计算(调用dec2bin函数)............................................................8二进制数转十进制数的计算(调用bin2dec函数)............................................................9三、附各按键的程序源代码......................................................................................10四、问题和解决方法..................................................................................................15五、心得体会..............................................................................................................15参考文献......................................................................................................................152/15计算器的效果图:3/15一、GUI设计界面:1.打开GUI输入Guide回车或者在工具栏上点击图标打开Guide窗口:2.添加按钮4/153.根据按钮的作用及视觉效果做一定的修改:双击按钮(PuchButton)进入按键属性修改显示字符串大小、字体和颜色,然后对按钮的位置进行排布,尽量使按钮集中在静态文本框下面。4.保存、添加功能函数把做好的按钮及静态文本框保存后自动弹出Editor的M文本,对然后对相应的pushbutton添加功能函数。以下是相应按钮的功能函数。(1)数字键编写在functionpushbutton1_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中输出。同理,分别在functionpushbutton2~10_Callback(hObject,eventdata,handles)下给1~9数字按键下编写此类程序。(2)符号键的编写functionpushbutton12_Callback(hObject,eventdata,handles)textString=get(handles.text1,'String');textString=strcat(textString,'÷');set(handles.text1,'String',textString)strcat的作用是将两个字符串连接起来,就是在已输入的存储数据textString后添加“÷”进行运算。然后执行set(handles.text1,'String',textString)。符号键‘-’、‘*’、‘/’与‘÷’的运算函数类似。“平方运算”,主要是由“^2”功能实现。5/15(3)运算符“=”的编写textString=get(handles.text1,'String');ans=eval(textString);“eval”的作用是将符号表达式转换成数值表达式。再由set(handles.text1,'String',ans)输出。(4)按键“←back”的编写textString=get(handles.text1,'String')w=length(textString)t=char(textString)textString=t(1:w-1)%将w个字符串转成w-1个,即删除了末位字符set(handles.text1,'String',textString)(5)按键“清空”的编写set(handles.text1,'String','')(6)按键“退出”的编写close(gcf);(7)按键“二进制数转十进制数”的编写textString=get(handles.text1,'String')e=bin2dec(textString);set(handles.text1,'String',e);(8)按键“十进制数转二进制数”的编写textString=get(handles.text1,'String');textString=strcat(textString,'dec2bin(');set(handles.text1,'String',textString)6/15二、计算器的使用除法运算(÷)平方运算(^2)7/15函数cos(∏/3)的计算函数arctan(∏/3)的计算8/15以2为底的对数的计算(log2)十进制数转二进制数的计算(调用dec2bin函数)9/15二进制数转十进制数的计算(调用bin2dec函数)经过计算,这些结果均与实际结果相吻合,计算器的功能实现的完好且能实现较大数值的运算,计算结果用科学技术法表示。10/15三、附各按键的程序源代码按键“0-9、+、-、×、÷、.、=、x^2”(通过get函数获得输入的字符,函数strcat获得相应字符,并用set函数进行显示输出):functionpushbutton1_Callback(hObject,eventdata,handles)textString=get(handles.text1,'String')textString=strcat(textString,'0')set(handles.text1,'String',textString)functionpushbutton2_Callback(hObject,eventdata,handles)textString=get(handles.text1,'String')textString=strcat(textString,'1')set(handles.text1,'String',