收藏 分销(赏)

用-MATLAB设计一个万年历复习课程.doc

上传人:w****g 文档编号:3791627 上传时间:2024-07-18 格式:DOC 页数:40 大小:642.50KB
下载 相关 举报
用-MATLAB设计一个万年历复习课程.doc_第1页
第1页 / 共40页
用-MATLAB设计一个万年历复习课程.doc_第2页
第2页 / 共40页
用-MATLAB设计一个万年历复习课程.doc_第3页
第3页 / 共40页
用-MATLAB设计一个万年历复习课程.doc_第4页
第4页 / 共40页
用-MATLAB设计一个万年历复习课程.doc_第5页
第5页 / 共40页
点击查看更多>>
资源描述

1、用 MATLAB设计一个万年历精品资料 课程论文用 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_push

2、button1_Callback”中编写代码.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.2添加按钮控件1、选取5个静态文本控件,用来定义“输入年

4、份”、“输入月份”、“星期”、“当月日历显示区”,以及显示每周的“日”、“一”、“二”、“三”、“四”、“五”、“六”;2、选取两个push button按钮空间用来定义“显示星期”、“显示日历”;3、添加两个编辑文本框控件用来输入具体的数字年份和月份;4、添加42个编辑文本框控件,用来显示具体的日期。(具体摆放如下图)2.3 根据控件的属性及视觉效果做一定的修改1、双击“输入年份”、“输入月份”、“星期”和“当月日历显示区”这4个静态文本框,在“String”文本框中输入相应的中文,将字体大小“FontSize”设置为20,其他默认即可。2、对于“星期”下方的静态文本框,“String”文本

5、框中不输入任何内容,将字体大小“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_pushbutton2”。5、对于42个编辑文本框,首先将“Enabl

6、e”属性中的“on”设置为“inactive”,使其转为静态文本框,并且保持控件的高亮状态;其次,在“String”文本框中都不输入任何内容;最后在“Tag”文本框中从左到右、按列依次输入“r1_edit”、“r2_edit”、“r42_edit”。2.4保存、添加功能函数把做好的按钮及静态文本框保存为“wannianli.fig”后自动弹出Editor的M文本,然后对相应的控件添加功能函数。以下是相应控件的功能函数的代码。(单击工具栏中的按钮可快速跳转到各个控件的回调函数)2.4.1在“nian_edit1_Callback”中编写代码function nian_edit1_Callback

7、(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, handles)input=str2num(get(hObject,String); % 输入月份if(isempty(input) set(hObj

8、ect,String,0)endif input=13 errordlg(月份不能超过12,警告) % 显示警告信息库endguidata(hObject,handles);2.4.3在“zhou_pushbutton1_Callback”中编写代码function zhou_pushbutton1_Callback(hObject, eventdata, handles)% 添加如下程序:h=日;一;二;三;四;五;六; % 显示结果set(handles.xingqi_text4,String,h); % 更新结构体guidata(hObject,handles);2.4.4在“rili_

9、pushbutton2_Callback”中编写代码function rili_pushbutton2_Callback(hObject, eventdata, handles)% 添加如下程序: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

10、 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%定义初始值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(mo

11、nth);A=zeros(n,1);S=S+1;%计算这个月的第一天是星期几w=mod(S,7);for k=1:n A(w+k)=k;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,St

12、ring,num2str(T(4);set(handles.r42_edit,String,num2str(T(5);guidata(hObject,handles);第三章 万年历的使用3.1运行单击本M文件编辑窗口中工具栏中的“运行”按钮,或单击GUIDE的输出编辑器中的工具栏中的按钮,创建功能GUI界面,如下图3.2输入 在图中输入年份为“2015”,输入月份为“2”,单击“显示星期”按钮和“显示日历”按钮,显示结果如下图3.3错误警告若在“输入月份”文本框中输入的数字超过12,则会弹出警告对话框提示错误。例如输入月份“13”,则弹出如下图所示警告窗口。第四章 改写界面注意到上图左上角名

13、称为“万年历”而不是“wannianli”,其实修改很简单,只需在输出编辑器界面中,单击鼠标右键,从弹出的快捷菜单中选择“Property Inspector”命令,打开界面属性窗口。将窗口的标题(Name属性)设置为“万年历”,关闭该窗口,并运行界面,显示结果就是创建的“万年历”窗口。在图中输入年份为“2015”,输入月份为“6”,单击“显示星期”按钮和“显示日历”按钮,显示结果就是所要创建的GUI界面。第五章 结论、问题解决与改进5.1结论与讨论:经过多次实验,本程序进行本月日历的显示及对应的星期的结果符合事实。5.2问题解决:如出现界面数字混乱,可能是因为42个文本框没有从上到下依次添加

14、,可以交换编辑文本框位置,直到显示的日历符合事实为止。5.3可以加以改进的地方:1可对GUI界面进行适当美化2可增加农历3加如节日和农历节气的显示第六章 心得体会目前流行的计算机日历程序,比较典型的是Windows各版本中的日历程序以及基础于该程序所开发的各种应用程序中的日历程序。然而,这些程序都千篇一律的局限在一个很短的时间范围内。(Windows各个版本一般都局限在1980年至2099年这一范围内),但是,在很多情况下,特别是在众多的科学研究领域中,一个时间跨度较大的日历程序是很有参考价值的。经过一个学期对数学软件的学习,我们学习了理论知识,了解了MATLAB这个软件,这些知识都为我们的下

15、一步学习打下了坚实的基础。通过课程设计,一方面是为了检查我们一个学期来我们学习的成果,另一方面也是为了让我们进一步的掌握和运用它,同时也让我们认清自己的不足之处和薄弱环节,加以弥补和加强。通过本次的MATLAB设计,让我对MATLAB尤其是GUI可视化图形界面的设计功能有了进一步的了解,认识到其功能的强大和丰富的内置函数及工具箱。在MATLAB万年历的设计中,了解关于MATLAB图形用户界面的部分空间的使用方法,利用MATLAB的GUI提供的很多实用控件,方便用于设计自己的图形界面。在万年历的编写过程中也体会到了做事情一顶要细心、认真。更加知道了要掌握好基础知识。还有体会到了成功的感觉!通过本

16、项课程设计也培养了我独立思考、综合运用所学有关相应知识的能力。参考文献【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 WANNIANL

17、I 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(Property,Value,.)

18、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 are passed to wannianli_OpeningFcn vi

19、a varargin.% *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 wannianli% Last Modified by GUIDE v2.5 17-May-2015 21:12:01% Begin initialization code - DO NOT EDITg

20、ui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, wannianli_OpeningFcn, . gui_OutputFcn, wannianli_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargo

21、ut1: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 visible.function wannianli_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.%

22、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 arguments to wannianli (see VARARGIN)% Choose default command line output for wannianlihandles.output = hObject;% Update handl

23、es structureguidata(hObject, handles);% UIWAIT makes wannianli 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 out

24、put 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 output from handles structurevarargout1 = handles.output;function nian_edit1_Callback(hObject, e

25、ventdata, 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 GUIDATA)% Hints: get(hObject,String) returns contents of nian_edit1 as text% str2double(get(hObject,String) returns content

26、s of nian_edit1 as a doubleinput=str2num(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)% event

27、data 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,defaultUicontrolBackgroundC

28、olor) 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 version of MATLAB% handles structure with handle

29、s 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_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and

30、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% - Executes during object creation, after setting all properties.function r1_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to

31、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,BackgroundColor), get(0,de

32、faultUicontrolBackgroundColor) 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 structure with handles and user data (see GUIDATA)% Hints: get(

33、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(hObject, eventdata, handles)% hObject handle to r2_edit (see GCBO)% eventdata reserv

34、ed - 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,defaultUicontrolBackgroundColor) set(h

35、Object,BackgroundColor,white);endfunction r3_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

36、r3_edit as text% str2double(get(hObject,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 versi

37、on 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(hObject,BackgroundColor,white);endfun

38、ction 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_edit as text% str2double(get(hObj

39、ect,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 future version of MATLAB% handles empty - handle

40、s 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,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,Str

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服