




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 供热管道清洗工程合同范本
- 公司借款给员工合同范本
- 合同范例加拿大
- 医疗设备出口合同范本
- 个人出租农机合同范本
- 分包单位合同范本
- 储罐制造合同范本
- 合同范本合同变更
- 产品合同范本模板
- 合同范本制定 推行
- 2024年《多媒体技术与应用》 考试题库及答案
- 注塑模具基础知识
- 公铁两用牵引车市场发展预测和趋势分析
- 3.1 导数的概念 课件 《高等数学》
- 2024江西南昌云上国脉(江西)数字技术限公司招聘1人重点基础提升难、易点模拟试题(共500题)附带答案详解
- 2024年湖南省长沙县高桥镇敬老院招聘院长历年高频考题难、易错点模拟试题(共500题)附带答案详解
- 2022-2023学年北京中桥外国语学校 高一数学文上学期摸底试题含解析
- 第2课古代希腊罗马(教学课件)-【中职专用】《世界历史》同步课堂(同课异构)(高教版2023•基础模块)
- FZT 81005-2017 绗缝制品行业标准
- 2024年北师大版五年级数学下册导学案
- 闪蒸罐计算完整版本
评论
0/150
提交评论