版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、-作者xxxx-日期xxxx用 MATLAB設(shè)計一個萬年歷【精品文檔】 課程論文用 MATLAB設(shè)計一個萬年歷課 程數(shù)學軟件學生姓名學 號手機號碼所在學院理學院所在班級信計1134任課教師提交時間2015年 06 月 07日目錄萬年歷的效果圖2第一章 設(shè)計目的與要求.31.1 設(shè)計目的.31.2 設(shè)計要求.3第二章 GUI界面設(shè)計32.1 打開GUI .32.2 添加按鈕控件.42.3 根據(jù)控件的屬性及視覺效果做一定的修改.52.4 保存、添加功能函數(shù).52.4.1 在“nian_edit1_Callback”中編寫代碼.52.4.2 在“yue_edit2_Callback”中編寫代碼.62
2、.4.3 在“zhou_pushbutton1_Callback”中編寫代碼.62.4.4 在“rili_pushbutton2_Callback”中編寫代碼.6第三章 萬年歷的使用.73.1 運行.83.2 輸入.83.3 錯誤警告.9第四章 改寫界面.10第五章 結(jié)論、問題解決及改進.10.101010第六章 心得體會.11參考文獻.11附錄:源程序代碼11萬年歷效果圖第一章 設(shè)計目的與要求:1.1設(shè)計目的:通過萬年歷程序的設(shè)計,培養(yǎng)學生綜合利用MATLAB進行程序設(shè)計的能力,加強函數(shù)的運用,提高軟件系統(tǒng)分析能力和程序文檔建立、歸納總結(jié)的能力,培養(yǎng)學生利用系統(tǒng)提供的標準函數(shù)及典型算法進行設(shè)
3、計,開發(fā)應(yīng)用軟件。 通過本項課程設(shè)計,可以培養(yǎng)獨立思考、 綜合運用所學有關(guān)相應(yīng)知識的能力,能更好的鞏固數(shù)學軟件課程學習的內(nèi)容,掌握 GUI界面設(shè)計的基本方法,更加了解了MATLAB的好處和其可用性! 1.2設(shè)計要求:設(shè)計一個萬年歷GUI界面,其界面布局如上圖,包括“輸入年份”、“輸入月份”、“顯示星期”、“顯示日歷”等控件。在界面上任意輸入某個具體年份和月份,單擊按鈕即可顯示本月的日歷及其對應(yīng)的星期(0表示沒有數(shù)字日期)。第二章 GUI界面設(shè)計:輸入Guide回車或者在工具欄上點擊圖標打開Guide窗口:1
4、、選取5個靜態(tài)文本控件,用來定義“輸入年份”、“輸入月份”、“星期”、“當月日歷顯示區(qū)”,以及顯示每周的“日”、“一”、“二”、“三”、“四”、“五”、“六”;2、選取兩個push button按鈕空間用來定義“顯示星期”、“顯示日歷”;3、添加兩個編輯文本框控件用來輸入具體的數(shù)字年份和月份;4、添加42個編輯文本框控件,用來顯示具體的日期。(具體擺放如下圖)2.3 根據(jù)控件的屬性及視覺效果做一定的修改1、雙擊“輸入年份”、“輸入月份”、“星期”和“當月日歷顯示區(qū)”這4個靜態(tài)文本框,在“String”文本框中輸入相應(yīng)的中文,將字體大小“FontSize”設(shè)置為20,其他默認即可。2、對于“星期
5、”下方的靜態(tài)文本框,“String”文本框中不輸入任何內(nèi)容,將字體大小“FontSize”設(shè)置為25,在“Tag”文本框中輸入“xingqi_text4”。3、對于輸入年份和月份的編輯文本框,在“String”文本框中輸入0,將字體大小“FontSize”設(shè)置為18,在“Tag”文本框中分別輸入“nian_edit1”和“yue_edit2”。4、對于兩個push button按鈕,在“String”文本框中分別輸入“顯示星期”和“顯示日期”,將字體大小“FontSize”都設(shè)置為20,在“Tag”文本框中分別輸入“zhou_pushbutton1”和“rili_pushbutton2”。5、
6、對于42個編輯文本框,首先將“Enable”屬性中的“on”設(shè)置為“inactive”,使其轉(zhuǎn)為靜態(tài)文本框,并且保持控件的高亮狀態(tài);其次,在“String”文本框中都不輸入任何內(nèi)容;最后在“Tag”文本框中從左到右、按列依次輸入“r1_edit”、“r2_edit”、···、“r42_edit”。2.4保存、添加功能函數(shù)把做好的按鈕及靜態(tài)文本框保存為“wannianli.fig”后自動彈出Editor的M文本,然后對相應(yīng)的控件添加功能函數(shù)。以下是相應(yīng)控件的功能函數(shù)的代碼。(單擊工具欄中的按鈕可快速跳轉(zhuǎn)到各個控件的回調(diào)函數(shù))2.4.1在“nian_edit1_Cal
7、lback”中編寫代碼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, eventdata, handle
8、s)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, eventdat
9、a, handles)% 添加如下程序:h='日''一''二''三''四''五''六' % 顯示結(jié)果set(handles.xingqi_text4,'String',h); % 更新結(jié)構(gòu)體guidata(hObject,handles);2.4.4在“rili_pushbutton2_Callback”中編寫代碼function rili_pushbutton2_Callback(hObject, eventdata, handles)% 添加如下程序:nian=g
10、et(handles.nian_edit1,'String');yue=get(handles.yue_edit2,'String');year=str2num(nian);month=str2num(yue);%找出各年12個月的天數(shù)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:m);end%定義
11、初始值run=0; %閏年初始值ping=0; %平年初始值%計算從第一年到前一年的閏年和平年的個數(shù)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%計算從第一年到當年前一個月的天數(shù)S=366*run+365*ping;for p=1:month-1 S=S+Y(p);end%獲得這個月的天數(shù)n=Y(month);A=zeros(n,1);S=S+1;%計算這個月的第一天是星期幾w=mod(S,7);for k=1:n A(w+k)=k;endT=A(1
12、:end);zeros(42-length(A),1); %沒有日期用0代替set(handles.r1_edit,'String',num2str(T(1); %顯示結(jié)果set(handles.r2_edit,'String',num2str(T(2);set(handles.r3_edit,'String',num2str(T(3);%以下類推,直到r40_edit(在此省略,但在M文件上必須全部寫上)%_1_edit,'String',num2str(T(4);42_edit,'String',num2str
13、(T(5);guidata(hObject,handles);第三章 萬年歷的使用單擊本M文件編輯窗口中工具欄中的“運行”按鈕,或單擊GUIDE的輸出編輯器中的工具欄中的按鈕,創(chuàng)建功能GUI界面,如下圖3.2輸入 在圖中輸入年份為“2015”,輸入月份為“2”,單擊“顯示星期”按鈕和“顯示日歷”按鈕,顯示結(jié)果如下圖若在“輸入月份”文本框中輸入的數(shù)字超過12,則會彈出警告對話框提示錯誤。例如輸入月份“13”,則彈出如下圖所示警告窗口。第四章 改寫界面注意到上圖左上角名稱為“萬年歷”而不是“wannianli”,其實修改很簡單,只需在輸出編輯器界面中,單擊鼠標右鍵,從彈出的快捷菜單中選擇“Prop
14、erty Inspector”命令,打開界面屬性窗口。將窗口的標題(Name屬性)設(shè)置為“萬年歷”,關(guān)閉該窗口,并運行界面,顯示結(jié)果就是創(chuàng)建的“萬年歷”窗口。在圖中輸入年份為“2015”,輸入月份為“6”,單擊“顯示星期”按鈕和“顯示日歷”按鈕,顯示結(jié)果就是所要創(chuàng)建的GUI界面。第五章 結(jié)論、問題解決與改進5.1結(jié)論與討論:經(jīng)過多次實驗,本程序進行本月日歷的顯示及對應(yīng)的星期的結(jié)果符合事實。5.2問題解決:如出現(xiàn)界面數(shù)字混亂,可能是因為42個文本框沒有從上到下依次添加,可以交換編輯文本框位置,直到顯示的日歷符合事實為止。5.3可以加以改進的地方:1可對GUI界面進行適當美化2可增加農(nóng)歷3加如節(jié)日
15、和農(nóng)歷節(jié)氣的顯示第六章 心得體會目前流行的計算機日歷程序,比較典型的是Windows各版本中的日歷程序以及基礎(chǔ)于該程序所開發(fā)的各種應(yīng)用程序中的日歷程序。然而,這些程序都千篇一律的局限在一個很短的時間范圍內(nèi)。(Windows各個版本一般都局限在1980年至2099年這一范圍內(nèi)),但是,在很多情況下,特別是在眾多的科學研究領(lǐng)域中,一個時間跨度較大的日歷程序是很有參考價值的。 經(jīng)過一個學期對數(shù)學軟件的學習,我們學習了理論知識,了解了MATLAB這個軟件,這些知識都為我們的下一步學習打下了堅實的基礎(chǔ)。通過課程設(shè)計,一方面是為了檢查我們一個學期來我們學習的成果,另一方面也是為了讓我們進一步的掌
16、握和運用它,同時也讓我們認清自己的不足之處和薄弱環(huán)節(jié),加以彌補和加強。 通過本次的MATLAB設(shè)計,讓我對MATLAB尤其是GUI可視化圖形界面的設(shè)計功能有了進一步的了解,認識到其功能的強大和豐富的內(nèi)置函數(shù)及工具箱。在MATLAB萬年歷的設(shè)計中,了解關(guān)于MATLAB圖形用戶界面的部分空間的使用方法,利用MATLAB的GUI提供的很多實用控件,方便用于設(shè)計自己的圖形界面。在萬年歷的編寫過程中也體會到了做事情一頂要細心、認真。更加知道了要掌握好基礎(chǔ)知識。還有體會到了成功的感覺!通過本項課程設(shè)計也培養(yǎng)了我獨立思考、 綜合運用所學有關(guān)相應(yīng)知識的能力。參考文獻【2】施曉紅、周佳.精通
17、GUI圖形界面教程M.北京:北京理工大學出版社.2003. 附錄:程序源代碼function varargout = wannianli(varargin)% WANNIANLI, by itself, creates a new WANNIANLI or raises the existing% singleton*.% H = WANNIANLI returns the handle to a new WANNIANLI or the handle to% the existing singleton*.% WANNIANLI('CALLBACK',hObject
18、,eventData,handles,.) calls the local% function named CALLBACK in WANNIANLI.M with the given input arguments.% WANNIANLI('Property','Value',.) creates a new WANNIANLI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before wanni
19、anli_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs 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: GUID
20、E, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help wannianli% Last Modified by GUIDE v2.5 17-May-2015 21:12:01% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . 'gui_Singleton', gui_Singleton, . 'gui_Open
21、ingFcn', wannianli_OpeningFcn, . 'gui_OutputFcn', wannianli_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gu
22、i_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before wannianli is made visible.function wannianli_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be de
23、fined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to wannianli (see VARARGIN)% Choose default command line output for wannianlihandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes wa
24、nnianli wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = wannianli_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% ev
25、entdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout1 = handles.output;function nian_edit1_Callback(hObject, eventdata, handles)% hObject handle to nian_edit1 (see G
26、CBO)% 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 nian_edit1 as text% str2double(get(hObject,'String') returns contents of nian_edit1 as a doubleinput=st
27、r2num(get(hObject,'String');if(isempty(input) set(hObject,'String','0')endguidata(hObject,handles);% - Executes during object creation, after setting all properties.function nian_edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to nian_edit1 (see GCBO)% eventdata
28、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,'BackgroundColor'), get(0,'defaultU
29、icontrolBackgroundColor') set(hObject,'BackgroundColor','white');end% - Executes on button press in zhou_pushbutton1.function zhou_pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to zhou_pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future vers
30、ion of MATLAB% handles structure with handles and user data (see GUIDATA)h='日''一''二''三''四''五''六'set(handles.xingqi_text4,'String',h);guidata(hObject,handles);function r1_edit_Callback(hObject, eventdata, handles)% hObject handle to r1_e
31、dit (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 r1_edit as text% str2double(get(hObject,'String') returns contents of r1_edit as a double% -
32、Executes during object creation, after setting all properties.function r1_edit_CreateFcn(hObject, eventdata, handles)% hObject 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:
33、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 r2_edit_Callback(hObject, eventdata,
34、 handles)% hObject handle to r2_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 r2_edit as text% str2double(get(hObject,'String') returns co
35、ntents of r2_edit as a double% - Executes during object creation, after setting all properties.function r2_edit_CreateFcn(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 af
36、ter 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');endfunction r3_
37、edit_Callback(hObject, eventdata, handles)% hObject handle to r3_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 r3_edit as text% str2double(get(hOb
38、ject,'String') returns contents of r3_edit as a double% - Executes during object creation, after setting all properties.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 emp
39、ty - 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,'BackgroundColor'
40、,'white');endfunction r4_edit_Callback(hObject, eventdata, handles)% hObject handle to r4_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 r4
41、_edit as text% str2double(get(hObject,'String') returns contents of r4_edit as a double% - Executes during object 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 futu
42、re 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,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(
43、hObject,'BackgroundColor','white');endfunction r5_edit_Callback(hObject, eventdata, handles)% hObject handle 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,'St
44、ring') returns contents of r5_edit as text% str2double(get(hObject,'String') returns contents of r5_edit as a double% - Executes during object creation, after setting all properties.function r5_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to r5_edit (see GCBO)% eventdata r
45、eserved - 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,'BackgroundColor'), get(0,'defaultUi
46、controlBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r6_edit_Callback(hObject, 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 GUI
47、DATA)% Hints: get(hObject,'String') returns contents of r6_edit as text% str2double(get(hObject,'String') 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 t
48、o r6_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,'Background
49、Color'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction 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 wi
50、th handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of r7_edit as text% str2double(get(hObject,'String') returns contents of r7_edit as a double% - Executes during object creation, after setting all properties.function r7_edit_CreateFcn(hObject, even
51、tdata, handles)% hObject handle to r7_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 && is
52、equal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');endfunction r8_edit_Callback(hObject, eventdata, handles)% hObject handle to r8_edit (see GCBO)% eventdata reserved - to be defined in a future versio
53、n of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents 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 future version of MATLAB% handles empty - handles not created until after all CreateFcns ca
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 45178-2024化學纖維抗氧化活性測定DPPH和ABTS法
- GB/T 45160-2024木工機床安全臥式鋸板機
- 湖南省岳陽市2024年中考第二次模擬考試數(shù)學試卷附答案
- 高一化學二課后習題(全)
- 2024屆百色市重點中學高考化學三模試卷含解析
- 2024高中地理第2章區(qū)域生態(tài)環(huán)境建設(shè)第2節(jié)第2課時熱帶雨林的開發(fā)與保護學案新人教版必修3
- 2024高中物理第三章磁場章末質(zhì)量評估三含解析粵教版選修3-1
- 2024高中語文第四單元創(chuàng)造形象詩文有別大鐵椎傳作業(yè)含解析新人教版選修中國古代詩歌散文欣賞
- 2024高考化學一輪復(fù)習專練48基本儀器的使用及藥品的存放含解析新人教版
- 2024高考化學一輪復(fù)習課練31物質(zhì)的制備含解析
- 2024政務(wù)服務(wù)綜合窗口人員能力與服務(wù)規(guī)范考試試題
- 第十五屆全國石油和化工行業(yè)職業(yè)技能競賽(化工總控工)考試題庫-下(判斷題)
- 羊肉購銷合同范本
- 2024五年級下冊語文組詞表
- 2024 smart社區(qū)運營全案服務(wù)項目
- JT∕T 1477-2023 系列2集裝箱 角件
- JT-T-566-2004軌道式集裝箱門式起重機安全規(guī)程
- 危險廢物處置項目實施方案
- 人教版初三化學上冊講義
- (完整版)共邊比例定理及其應(yīng)用
- 村情要素模板
評論
0/150
提交評論