




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 課程論文用 MATLAB設計一個萬年歷課 程數學軟件學生姓名學 號手機號碼所在學院理學院所在班級信計1134任課教師提交時間2015年 06 月 07日目錄萬年歷的效果圖2第一章 設計目的與要求.31.1 設計目的.31.2 設計要求.3第二章 GUI界面設計32.1 打開GUI .32.2 添加按鈕控件.42.3 根據控件的屬性及視覺效果做一定的修改.52.4 保存、添加功能函數.52.4.1 在“nian_edit1_Callback”中編寫代碼.52.4.2 在“yue_edit2_Callback”中編寫代碼.62.4.3 在“zhou_pushbutton1_Callback”中編
2、寫代碼.62.4.4 在“rili_pushbutton2_Callback”中編寫代碼.6第三章 萬年歷的使用.73.1 運行.83.2 輸入.83.3 錯誤警告.9第四章 改寫界面.10第五章 結論、問題解決及改進.105.1結論與討論.105.2問題解決105.3可以加以改進的地方10第六章 心得體會.11參考文獻.11附錄:源程序代碼11萬年歷效果圖第一章 設計目的與要求:1.1設計目的:通過萬年歷程序的設計,培養學生綜合利用MATLAB進行程序設計的能力,加強函數的運用,提高軟件系統分析能力和程序文檔建立、歸納總結的能力,培養學生利用系統提供的標準函數及典型算法進行設計,開發應用軟件
3、。 通過本項課程設計,可以培養獨立思考、 綜合運用所學有關相應知識的能力,能更好的鞏固數學軟件課程學習的內容,掌握 GUI界面設計的基本方法,更加了解了MATLAB的好處和其可用性! 1.2設計要求:設計一個萬年歷GUI界面,其界面布局如上圖,包括“輸入年份”、“輸入月份”、“顯示星期”、“顯示日歷”等控件。在界面上任意輸入某個具體年份和月份,單擊按鈕即可顯示本月的日歷及其對應的星期(0表示沒有數字日期)。第二章 GUI界面設計:2.1打開GUI輸入Guide回車或者在工具欄上點擊圖標打開Guide窗口:2
4、.2添加按鈕控件1、選取5個靜態文本控件,用來定義“輸入年份”、“輸入月份”、“星期”、“當月日歷顯示區”,以及顯示每周的“日”、“一”、“二”、“三”、“四”、“五”、“六”;2、選取兩個push button按鈕空間用來定義“顯示星期”、“顯示日歷”;3、添加兩個編輯文本框控件用來輸入具體的數字年份和月份;4、添加42個編輯文本框控件,用來顯示具體的日期。(具體擺放如下圖)2.3 根據控件的屬性及視覺效果做一定的修改1、雙擊“輸入年份”、“輸入月份”、“星期”和“當月日歷顯示區”這4個靜態文本框,在“String”文本框中輸入相應的中文,將字體大小“FontSize”設置為20,其他默認即
5、可。2、對于“星期”下方的靜態文本框,“String”文本框中不輸入任何內容,將字體大小“FontSize”設置為25,在“Tag”文本框中輸入“xingqi_text4”。3、對于輸入年份和月份的編輯文本框,在“String”文本框中輸入0,將字體大小“FontSize”設置為18,在“Tag”文本框中分別輸入“nian_edit1”和“yue_edit2”。4、對于兩個push button按鈕,在“String”文本框中分別輸入“顯示星期”和“顯示日期”,將字體大小“FontSize”都設置為20,在“Tag”文本框中分別輸入“zhou_pushbutton1”和“rili_pushbu
6、tton2”。5、對于42個編輯文本框,首先將“Enable”屬性中的“on”設置為“inactive”,使其轉為靜態文本框,并且保持控件的高亮狀態;其次,在“String”文本框中都不輸入任何內容;最后在“Tag”文本框中從左到右、按列依次輸入“r1_edit”、“r2_edit”、···、“r42_edit”。2.4保存、添加功能函數把做好的按鈕及靜態文本框保存為“wannianli.fig”后自動彈出Editor的M文本,然后對相應的控件添加功能函數。以下是相應控件的功能函數的代碼。(單擊工具欄中的按鈕可快速跳轉到各個控件的回調函數)2.4.1在“nian_
7、edit1_Callback”中編寫代碼function nian_edit1_Callback(hObject, eventdata, handles)% 添加如下程序:input=str2num(get(hObject,'String'); % 輸入年份if(isempty(input) set(hObject,'String','0')endguidata(hObject,handles);2.4.2在“yue_edit2_Callback”中編寫代碼function yue_edit2_Callback(hObject, eventdat
8、a, handles)input=str2num(get(hObject,'String'); % 輸入月份if(isempty(input) set(hObject,'String','0')endif input>=13 errordlg('月份不能超過12','警告') % 顯示警告信息庫endguidata(hObject,handles);2.4.3在“zhou_pushbutton1_Callback”中編寫代碼function zhou_pushbutton1_Callback(hObject,
9、 eventdata, handles)% 添加如下程序:h='日''一''二''三''四''五''六' % 顯示結果set(handles.xingqi_text4,'String',h); % 更新結構體guidata(hObject,handles);2.4.4在“rili_pushbutton2_Callback”中編寫代碼function rili_pushbutton2_Callback(hObject, eventdata, handles)% 添加如下
10、程序:nian=get(handles.nian_edit1,'String');yue=get(handles.yue_edit2,'String');year=str2num(nian);month=str2num(yue);%找出各年12個月的天數for m=1:12 if mod(year,4)=0&mod(year,100)=0|mod(year,400)=0 D=31 29 31 30 31 30 31 31 30 31 30 31; else D=31 28 31 30 31 30 31 31 30 31 30 31; end Y=D(1:
11、m);end%定義初始值run=0; %閏年初始值ping=0; %平年初始值%計算從第一年到前一年的閏年和平年的個數for q=1:year-1 if(mod(q,4)=0&mod(q,100)=0)|mod(q,400)=0 run=run+1; else ping=ping+1; endend%計算從第一年到當年前一個月的天數S=366*run+365*ping;for p=1:month-1 S=S+Y(p);end%獲得這個月的天數n=Y(month);A=zeros(n,1);S=S+1;%計算這個月的第一天是星期幾w=mod(S,7);for k=1:n A(w+k)=k
12、;endT=A(1:end);zeros(42-length(A),1); %沒有日期用0代替set(handles.r1_edit,'String',num2str(T(1); %顯示結果set(handles.r2_edit,'String',num2str(T(2);set(handles.r3_edit,'String',num2str(T(3);%以下類推,直到r40_edit(在此省略,但在M文件上必須全部寫上)%_set(handles.r41_edit,'String',num2str(T(4);set(handl
13、es.r42_edit,'String',num2str(T(5);guidata(hObject,handles);第三章 萬年歷的使用3.1運行單擊本M文件編輯窗口中工具欄中的“運行”按鈕,或單擊GUIDE的輸出編輯器中的工具欄中的按鈕,創建功能GUI界面,如下圖3.2輸入 在圖中輸入年份為“2015”,輸入月份為“2”,單擊“顯示星期”按鈕和“顯示日歷”按鈕,顯示結果如下圖3.3錯誤警告若在“輸入月份”文本框中輸入的數字超過12,則會彈出警告對話框提示錯誤。例如輸入月份“13”,則彈出如下圖所示警告窗口。第四章 改寫界面注意到上圖左上角名稱為“萬年歷”而不是“wannia
14、nli”,其實修改很簡單,只需在輸出編輯器界面中,單擊鼠標右鍵,從彈出的快捷菜單中選擇“Property Inspector”命令,打開界面屬性窗口。將窗口的標題(Name屬性)設置為“萬年歷”,關閉該窗口,并運行界面,顯示結果就是創建的“萬年歷”窗口。在圖中輸入年份為“2015”,輸入月份為“6”,單擊“顯示星期”按鈕和“顯示日歷”按鈕,顯示結果就是所要創建的GUI界面。第五章 結論、問題解決與改進5.1結論與討論:經過多次實驗,本程序進行本月日歷的顯示及對應的星期的結果符合事實。5.2問題解決:如出現界面數字混亂,可能是因為42個文本框沒有從上到下依次添加,可以交換編輯文本框位置,直到顯示
15、的日歷符合事實為止。5.3可以加以改進的地方:1可對GUI界面進行適當美化2可增加農歷3加如節日和農歷節氣的顯示第六章 心得體會目前流行的計算機日歷程序,比較典型的是Windows各版本中的日歷程序以及基礎于該程序所開發的各種應用程序中的日歷程序。然而,這些程序都千篇一律的局限在一個很短的時間范圍內。(Windows各個版本一般都局限在1980年至2099年這一范圍內),但是,在很多情況下,特別是在眾多的科學研究領域中,一個時間跨度較大的日歷程序是很有參考價值的。 經過一個學期對數學軟件的學習,我們學習了理論知識,了解了MATLAB這個軟件,這些知識都為我們的下一步學習打下了堅實的基
16、礎。通過課程設計,一方面是為了檢查我們一個學期來我們學習的成果,另一方面也是為了讓我們進一步的掌握和運用它,同時也讓我們認清自己的不足之處和薄弱環節,加以彌補和加強。 通過本次的MATLAB設計,讓我對MATLAB尤其是GUI可視化圖形界面的設計功能有了進一步的了解,認識到其功能的強大和豐富的內置函數及工具箱。在MATLAB萬年歷的設計中,了解關于MATLAB圖形用戶界面的部分空間的使用方法,利用MATLAB的GUI提供的很多實用控件,方便用于設計自己的圖形界面。在萬年歷的編寫過程中也體會到了做事情一頂要細心、認真。更加知道了要掌握好基礎知識。還有體會到了成功的感覺!通過本項課程設計
17、也培養了我獨立思考、 綜合運用所學有關相應知識的能力。參考文獻【1】楊德平、趙維加、管殿柱.MATLAB基礎教程.機械工業出版社.2014.11【2】施曉紅、周佳.精通GUI圖形界面教程M.北京:北京理工大學出版社.2003.【3】羅華飛.MATLAB GUI設計學習手記M.北京:北京航空航天大學出版社.2009.8.1 附錄:程序源代碼function varargout = wannianli(varargin)% WANNIANLI MATLAB code for wannianli.fig% WANNIANLI, by itself, creates a new W
18、ANNIANLI or raises the existing% singleton*.% H = WANNIANLI returns the handle to a new WANNIANLI or the handle to% the existing singleton*.% WANNIANLI('CALLBACK',hObject,eventData,handles,.) calls the local% function named CALLBACK in WANNIANLI.M with the given input arguments.% WANNIANLI(&
19、#39;Property','Value',.) creates a new WANNIANLI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before wannianli_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs
20、are passed to wannianli_OpeningFcn via varargin.% *See GUI Options on GUIDE's 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 wannianli% Last Modified by GUIDE v2.5 17-May-2
21、015 21:12:01% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . 'gui_Singleton', gui_Singleton, . 'gui_OpeningFcn', wannianli_OpeningFcn, . 'gui_OutputFcn', wannianli_OutputFcn, . 'gui_LayoutFcn', , . 'gui
22、_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before wannianli is made visib
23、le.function wannianli_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, 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 command line arg
24、uments to wannianli (see VARARGIN)% Choose default command line output for wannianlihandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes wannianli wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the
25、command line.function varargout = wannianli_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)
26、% Get default command line output from handles structurevarargout1 = handles.output;function nian_edit1_Callback(hObject, eventdata, handles)% hObject handle to nian_edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see
27、GUIDATA)% Hints: get(hObject,'String') returns contents of nian_edit1 as text% str2double(get(hObject,'String') returns contents of nian_edit1 as a doubleinput=str2num(get(hObject,'String');if(isempty(input) set(hObject,'String','0')endguidata(hObject,handles)
28、;% - Executes during object creation, after setting all properties.function nian_edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to nian_edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns cal
29、led% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');end% - Executes on button press in zh
30、ou_pushbutton1.function zhou_pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to zhou_pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)h='日''一''二''三'
31、9;四''五''六'set(handles.xingqi_text4,'String',h);guidata(hObject,handles);function r1_edit_Callback(hObject, eventdata, handles)% hObject handle to r1_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user
32、data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r1_edit as text% str2double(get(hObject,'String') returns contents of r1_edit as a double% - Executes during object creation, after setting all properties.function r1_edit_CreateFcn(hObject, eventdata, handles)% hOb
33、ject handle to r1_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,
34、39;BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r2_edit_Callback(hObject, eventdata, handles)% hObject handle to r2_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles
35、 structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r2_edit as text% str2double(get(hObject,'String') returns contents of r2_edit as a double% - Executes during object creation, after setting all properties.function r2_edit_CreateFcn(
36、hObject, eventdata, handles)% hObject handle to r2_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc
37、&& isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r3_edit_Callback(hObject, eventdata, handles)% hObject handle to r3_edit (see GCBO)% eventdata reserved - to be defined in a
38、future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r3_edit as text% str2double(get(hObject,'String') returns contents of r3_edit as a double% - Executes during object creation, after setting all prope
39、rties.function r3_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r3_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows
40、.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r4_edit_Callback(hObject, eventdata, handles)% hObject handle to r4_edit (see GCBO)% eventda
41、ta reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r4_edit as text% str2double(get(hObject,'String') returns contents of r4_edit as a double% - Executes during object
42、creation, after setting all properties.function r4_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r4_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually h
43、ave a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r5_edit_Callback(hObject, eventdata, handles)% hObject hand
44、le to r5_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r5_edit as text% str2double(get(hObject,'String') returns contents of r5_edit as a
45、double% - Executes during object creation, after setting all properties.function r5_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r5_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns call
46、ed% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r6_edit_Callback(hObject,
47、eventdata, handles)% hObject handle to r6_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r6_edit as text% str2double(get(hObject,'String')
48、returns contents of r6_edit as a double% - Executes during object creation, after setting all properties.function r6_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r6_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not create
49、d until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfu
50、nction r7_edit_Callback(hObject, eventdata, handles)% hObject handle to r7_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r7_edit as text% str2doub
51、le(get(hObject,'String') returns contents of r7_edit as a double% - Executes during object creation, after setting all properties.function r7_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r7_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% h
52、andles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'Background
53、Color','white');endfunction r8_edit_Callback(hObject, eventdata, handles)% hObject handle to r8_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns cont
54、ents of r8_edit as text% str2double(get(hObject,'String') returns contents of r8_edit as a double% - Executes during object creation, after setting all properties.function r8_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r8_edit (see GCBO)% eventdata reserved - to be defined in a futu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 熱力設計合同
- 電腦采購合同
- 恒溫箱企業數字化轉型與智慧升級戰略研究報告
- 2025年造紙色漿項目發展計劃
- 冶金級稀土金屬企業ESG實踐與創新戰略研究報告
- 電動坡口機企業縣域市場拓展與下沉戰略研究報告
- 道路交通協管服務企業ESG實踐與創新戰略研究報告
- 2025年冷鏈裝備項目合作計劃書
- 玻璃制光學元件戰略市場規劃報告
- 中國石油大慶石化分公司高校畢業生招聘筆試真題2024
- DB43T 1491-2018 貴鉛中砷、鉍、銅和銻量的測定 電感耦合等離子體發射光譜法
- 聲樂課課件教學
- 保密法實施條例培訓
- 泰山產業領軍人才申報書
- 《沿海灘涂鹽堿地機插水稻高產栽培技術規程(報批稿)》編制說明
- GB/T 44395-2024激光雷達測風數據可靠性評價技術規范
- 2024年四川成都市成華區“蓉漂人才薈”事業單位招聘高層次人才歷年高頻500題難、易錯點模擬試題附帶答案詳解
- 衛浴產品經銷合同模板
- 2024年浙江省金華市東陽市橫店鎮三校中考二模道德與法治試題(原卷版)
- 人教版(2024新版)九年級上冊化學:第四單元 跨學科實踐活動3《水質檢測及自制凈水器》教案教學設計
- 杭州市上城區政務服務中心招聘筆試真題2022
評論
0/150
提交評論