matlabGUI設(shè)計(jì)簡(jiǎn)易科學(xué)計(jì)算器_第1頁(yè)
matlabGUI設(shè)計(jì)簡(jiǎn)易科學(xué)計(jì)算器_第2頁(yè)
matlabGUI設(shè)計(jì)簡(jiǎn)易科學(xué)計(jì)算器_第3頁(yè)
matlabGUI設(shè)計(jì)簡(jiǎn)易科學(xué)計(jì)算器_第4頁(yè)
matlabGUI設(shè)計(jì)簡(jiǎn)易科學(xué)計(jì)算器_第5頁(yè)
已閱讀5頁(yè),還剩19頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上MATLAB大作業(yè)班級(jí):姓名:學(xué)號(hào):計(jì)算器 題目本題目通過(guò)MATLAB的gui程序設(shè)計(jì)較為簡(jiǎn)單,在gui設(shè)計(jì)中主要用到三種控件,文本編輯框(edit text),靜態(tài)文本框(Static text),命令按鈕(push button)。然后在通過(guò)各個(gè)按鈕的回調(diào)函數(shù),實(shí)現(xiàn)簡(jiǎn)單的計(jì)算功能。 1、功能介紹(1)具有友好的用戶圖形界面。實(shí)現(xiàn)十進(jìn)制數(shù)的加、減、乘、除、乘方、開(kāi)方等簡(jiǎn)單計(jì)算。(2)具有科學(xué)計(jì)算函數(shù),包括(反)正弦、(反)余弦、(反)正切、(反)余切、開(kāi)方、指數(shù)等函數(shù)運(yùn)行。(注:三角函數(shù)計(jì)算的是弧度而不是角度)。(3)有清除鍵,能清除操作。 2、功能實(shí)現(xiàn)程序由兩個(gè)部

2、分組成:MATLAB代碼(.m文件)和GUI圖形(.fig)。程序使用的流程:直接利用圖形界面中的按鍵鍵入所需數(shù)值、運(yùn)算符等即可得出結(jié)果。備注:軟件版本:MATLAB 2011b首先用MATLAB GUI功能,在繪制一個(gè)靜態(tài)文本框和一個(gè)文本編輯框,以及33個(gè)命令按鈕,調(diào)整好各控件大小、顏色,整體布局如圖所示:(附錄中有相關(guān)屬性修改介紹)然后通過(guò)雙擊各個(gè)按鈕來(lái)改寫(xiě)其屬性,在m文件中編寫(xiě)其回調(diào)函數(shù),最后在運(yùn)行調(diào)試。2.1 各功能界面設(shè)計(jì)GUI設(shè)計(jì)界面:注:底部邊框用(Panel)工具添加,有兩種設(shè)計(jì)順序。(1、先加底部邊框,再在底部邊框上畫(huà)功能鍵。2、先畫(huà)功能鍵,布好局,畫(huà)底框,全選功能鍵拖動(dòng)到底

3、框上。)2.2 各功能模塊實(shí)現(xiàn)(可根據(jù)需要增減功能鍵)算法設(shè)計(jì):1. 數(shù)字鍵設(shè)計(jì):09以及小數(shù)點(diǎn)函數(shù)都一樣,只是參數(shù)不同:例如:按鍵1響應(yīng):global jjtextString = get(handles.text1,String);if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,1) ;elsetextString =strcat(textString,1);set(handles.text1,String,textString)endjj=0;2. 四則運(yùn)算函數(shù):+功能響應(yīng):textString = get(hand

4、les.text1,String);textString =strcat(textString,+);set(handles.text1,String,textString)-功能響應(yīng):textString = get(handles.text1,String);textString =strcat(textString,-);set(handles.text1,String,textString)功能響應(yīng):textString = get(handles.text1,String);textString =strcat(textString,*);set(handles.text1,Stri

5、ng,textString)功能響應(yīng):textString = get(handles.text1,String);textString =strcat(textString,/);set(handles.text1,String,textString)3. 科學(xué)計(jì)算函數(shù):例如:sin功能響應(yīng):textString = get(handles.text1,String);if(strcmp(textString,0.)=1)set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=sin(a);set(handles.tex

6、t1,String,a)end4. 退格鍵(DEL):通過(guò)取屏幕值,計(jì)算出其字符長(zhǎng)度,然后取其前N-1項(xiàng)的值來(lái)實(shí)現(xiàn)退格:global jjtextString = get(handles.text1,String);if(strcmp(textString,0.)=1)&(jj=0)set(handles.text1,String,0.) ;elsess=char(textString);l=length(textString);textString=ss(1:l-1);set(handles.text1,String,textString)endjj=0;5. 清屏鍵函數(shù)(AC):set(h

7、andles.text1,String,0.) ;2.3 各模塊程序添加方法選中一個(gè)需添加程序的功能鍵,右擊,View Callbacks,Callback,出現(xiàn)如下圖所示界面。(紅色框中為所需添加的程序)其他功能鍵添加方法類似。2.4 各模塊實(shí)現(xiàn)結(jié)果(1)數(shù)字鍵:(2)四則運(yùn)算函數(shù):(3)科學(xué)計(jì)算函數(shù):Cos0的計(jì)算結(jié)果:arctan2的計(jì)算結(jié)果:經(jīng)過(guò)計(jì)算,這些結(jié)果均與實(shí)際結(jié)果相吻合,計(jì)算器的功能實(shí)現(xiàn)的較為完好。 3、程序總結(jié):(1)小數(shù)點(diǎn)可以連續(xù)輸入。解決方法是:用strfind函數(shù)查看文本框里有幾個(gè)小數(shù)點(diǎn),如果已經(jīng)有一個(gè)了,再按小數(shù)點(diǎn)就保持不變。(2)按過(guò)運(yùn)算符號(hào)后一個(gè)數(shù)不等于一個(gè)數(shù),比

8、如:輸入1,按等號(hào),會(huì)出來(lái)一個(gè)3,經(jīng)過(guò)長(zhǎng)時(shí)間分析得知,這是由于在按運(yùn)算符號(hào)時(shí),系統(tǒng)記錄了文本框里的數(shù)但沒(méi)有清空,才會(huì)出現(xiàn)這種問(wèn)題。解決方法是再申請(qǐng)一個(gè)不同于加減乘除的另一個(gè)符號(hào),并將按過(guò)運(yùn)算符后記錄的數(shù)值置0。 4、心得體會(huì):通過(guò)本次的MATLAB課程設(shè)計(jì),讓我對(duì)MATLAB尤其是其GUI設(shè)計(jì)的功能有了進(jìn)一步的了解,認(rèn)識(shí)到了它功能的強(qiáng)大。在MATLAB簡(jiǎn)單計(jì)算器的設(shè)計(jì)中,了解了關(guān)于MATLAB圖形用戶界面的部分控件的使用方法;利用MATLAB的GUI提供的很多實(shí)用的控件,方便用于設(shè)計(jì)屬于自己的圖形界面和自己所需要實(shí)現(xiàn)的功能。 5、附錄:(1) 功能塊屬性修改表(雙擊功能塊可進(jìn)入)(2)主要程序

9、function varargout = untitled(varargin)%UNTITLED M-file for untitled.fig% UNTITLED, by itself, creates a new UNTITLED or raises the existing% singleton*.% H = UNTITLED returns the handle to a new UNTITLED or the handle to% the existing singleton*.% UNTITLED(Property,Value,.) creates a new UNTITLED u

10、sing the% given property value pairs. Unrecognized properties are passed via% varargin to untitled_OpeningFcn. This calling syntax produces a% warning when there is an existing singleton*.% UNTITLED(CALLBACK) and UNTITLED(CALLBACK,hObject,.) call the% local function named CALLBACK in UNTITLED.M with

11、 the given input% arguments.% *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help untitled % Last Modified by GUIDE v2.5 19-Dec-2013 11:25:45 % Begin initialization

12、code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, untitled_OpeningFcn, . gui_OutputFcn, untitled_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);end

13、if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT % - Executes just before untitled is made visible.function untitled_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args,

14、 see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin unrecognized PropertyName/PropertyValue pairs from the% command line (see VARARGIN) % Choose default command line output f

15、or untitledhandles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes untitled wait for user response (see UIRESUME)% uiwait(handles.figure1);global jj ;set(handles.text1,String,0.);jj=0; % - Outputs from this function are returned to the command line.function vara

16、rgout = untitled_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Get default command line

17、output from handles structurevarargout1 = handles.output; % - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles

18、 and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,1) ;elsetextString =strcat(textString,1);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton2.function pushbutton2_Callback(hO

19、bject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,Stri

20、ng,2) ;elsetextString =strcat(textString,2);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB

21、% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,3) ;elsetextString =strcat(textString,3);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton4.

22、function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=

23、1)&(jj=0) set(handles.text1,String,4) ;elsetextString =strcat(textString,4);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defin

24、ed in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,5) ;elsetextString =strcat(textString,5);set(handles.text1,String,textString) endjj=0; % - Executes

25、 on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,St

26、ring); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,6) ;elsetextString =strcat(textString,6);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)%

27、eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,7) ;elsetextString =strcat(textString,7);set(handles.text1,String,t

28、extString) endjj=0; % - Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjt

29、extString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,8) ;elsetextString =strcat(textString,8);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject ha

30、ndle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,9) ;elsetextString =strcat(textStri

31、ng,9);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles an

32、d user data (see GUIDATA)global jjtextString = get(handles.text1,String); if(strcmp(textString,0.)=1)&(jj=0) set(handles.text1,String,0) ;elsetextString =strcat(textString,0);set(handles.text1,String,textString) endjj=0; % - Executes on button press in pushbutton12.function pushbutton12_Callback(hOb

33、ject, eventdata, handles)% hObject handle to pushbutton12 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jj textString = get(handles.text1,String);if(strcmp(textString,0.)=1) set(handles.text1,String,0.)

34、; jj=1;elsetextString =strcat(textString,.);set(handles.text1,String,textString)end % - Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)% hObject handle to pushbutton13 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% h

35、andles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);textString =strcat(textString,/);set(handles.text1,String,textString) % - Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, eventdata, handles)% hObject handle to pushbutton

36、14 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);if(strcmp(textString,0.)=1) set(handles.text1,String,() ;elsetextString =strcat(textString,();set(handles.text1,String,tex

37、tString)end % - Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = ge

38、t(handles.text1,String);if(strcmp(textString,0.)=1) set(handles.text1,String,) ;elsetextString =strcat(textString,);set(handles.text1,String,textString)end % - Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)% hObject handle to pushbutton17 (see GC

39、BO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);textString =strcat(textString,-);set(handles.text1,String,textString) % - Executes on button press in pushbutton18.function pushbutt

40、on18_Callback(hObject, eventdata, handles)% hObject handle to pushbutton18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);% if(strcmp(textString,0.)=1)% set(handles.text1,S

41、tring,0.) ;% else% pushbutton20 b c = strread(textString, %f %c %f);% clear ans;% % switch b% case *% ans=pushbutton20*c;% case /% if (c=0)% ans=Error Divided by zero;% else% ans=pushbutton20/c;% end% case -% ans=pushbutton20-c;% case +% ans=pushbutton20+c;% % endans =eval(textString);set(handles.te

42、xt1,String,ans) % - Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)% hObject handle to pushbutton19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString

43、= get(handles.text1,String);textString =strcat(textString,+);set(handles.text1,String,textString) % - Executes on button press in pushbutton20.function pushbutton20_Callback(hObject, eventdata, handles)% hObject handle to pushbutton20 (see GCBO)% eventdata reserved - to be defined in a future versio

44、n of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);%strcmp(textString,0.)if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=acot(a);set(handles.text1,String,a)end % - Executes on button press in pushb

45、utton21.function pushbutton21_Callback(hObject, eventdata, handles)% hObject handle to pushbutton21 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);%strcmp(textString,0.)if(

46、strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=sin(a);set(handles.text1,String,a)end % - Executes on button press in pushbutton22.function pushbutton22_Callback(hObject, eventdata, handles)% hObject handle to pushbutton22 (see GCBO)% eventdata reserved - to

47、be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);%strcmp(textString,0.)if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=cos(a);set(handles.text1,String,a)end % - Execu

48、tes on button press in pushbutton23.function pushbutton23_Callback(hObject, eventdata, handles)% hObject handle to pushbutton23 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,Strin

49、g);%strcmp(textString,0.)if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=tan(a);set(handles.text1,String,a)end % - Executes on button press in pushbutton24.function pushbutton24_Callback(hObject, eventdata, handles)% hObject handle to pushbutton24 (see GCB

50、O)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textString = get(handles.text1,String);%strcmp(textString,0.)if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=log2(a);set(handles

51、.text1,String,a)end % - Executes on button press in pushbutton26.function pushbutton26_Callback(hObject, eventdata, handles)% hObject handle to pushbutton26 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)textStr

52、ing = get(handles.text1,String);%strcmp(textString,0.)if(strcmp(textString,0.)=1) set(handles.text1,String,0.) ;elsea = strread(textString, %f);a=log10(a);set(handles.text1,String,a)end % - Executes on button press in pushbutton27.function pushbutton27_Callback(hObject, eventdata, handles)% hObject handle to pushbutton27 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global jjtextString = get(handles.text1,String)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論