Stephen J.Chapman《MATLAB 编程(第二版) 》第四章
%
% Purpose:
% This program calculates the day of year corresponding % to a specified date. It illustrates the use switch % and for constructs. %
% Record of revisions:
% Date Programmer Description of change
% ==== ========== ===================== % 12/07/98 S. J. Chapman Original code %
% Define variables:
% day --Day (dd) % day_of_year --Day of year % ii --Loop index
% leap_day --Extra day for leap year % month --Month (mm) % year --Year(yyyy)
% Get day, month, and year to convert
disp('This program calculates the day of year given the '); disp('current date.');
month = input('Enter current month (1-12):'); day = input('Enter current day(1-31):'); year = input('Enter current year(yyyy): ');
% Check for leap year, and add extra day if necessary if mod(year,400) == 0
leap_day = 1; % Years divisible by 400 are leap years elseif mod(year,100) == 0
leap_day = 0; % Other centuries are not leap years elseif mod(year,4) == 0
leap_day = 1; % Otherwise every 4th year is a leap year else
leap_day = 0; % Other years are not leap years end
% Calculate day of year by adding current day to the % days in previous months. day_of_year = day; for ii = 1:month - 1
% Add days in months from January to last month switch (ii)
case {1,3,5,7,8,10,12},
day_of_year = day_of_year + 31; case {4,6,9,11},
day_of_year = day_of_year + 30; case 2,
day_of_year = day_of_year + 28 + leap_day; end end
% Tell user
fprintf('The date %2d/%2d/%4d is day of year %d.\n', ... month, day, year, day_of_year); 我们用下面已知的结果来检测这个程序。
1.1999年不是闰年。它的1月1号对应的day of year是1,12月31号必定对应的是365。
2.2000年是一个闰年。它的1月1号对应的day of year是1,12月31号必定对应的是366。
Stephen J.Chapman《MATLAB 编程(第二版) 》第一章_工学_高等教育_教育专区。Stephen J.Chapman《MATLAB 编程(第二版) 》郑碧波翻译 Matlab 中文论坛首发 http:...
Stephen J.Chapman《MATLAB 编程(第二版) 》第二章Stephen J.Chapman《MATLAB 编程(第二版) 》第二章隐藏>> 郑碧波翻译 Matlab 中文论坛首发 http://www.iLo...
Stephen J.Chapman《MATLAB 编程(第二版) 》第三章Stephen J.Chapman《MATLAB 编程(第二版) 》第三章隐藏>> 郑碧波翻译 Matlab 中文论坛首发 http://www.iLove...
Stephen J.Chapman《MATLAB 编程(第二版) 》第六章Stephen J.Chapman《MATLAB 编程(第二版) 》第六章隐藏>> 郑碧波翻译 Matlab 中文论坛首发 http://www.iLo...
Matlab编程 第四版(Stephen J.Chapman)Quiz部分答案_计算机软件及应用_IT/计算机_专业资料。Matlab编程 第四版 (Stephen J.ChapmanQuiz答案PD...
郑碧波翻译 Matlab 中文论坛首发 http://www.iLoveMatlab.cn 前言 本文为 Stephen J.Chapman《MATLAB 编程(第二版) 》英文影印版的中文译本,这本 书对初学者很...
Chapman 著 邢树军 郑碧波 译 前言郑碧波本文为 Stephen J.Chapman《MATLAB 编程(第二版) 》英文影印版的中文译本,这本 书对初学者很好的入门教材。之前从网...
matlab编程英文版(Stephen J. Chapman )课后答案1_工学_高等教育_教育专区。matlab编程第二版Stephen J. ChapmanMATLAB MATLAB Programming for Enginees Enginees 姓名...
S.J.Chapman《MATLAB编程》中文版修正版_部分7_信息与通信_工程科技_专业资料。...>> cellstring{1} = 'Stephen J. Chapman'; >> cellstring{2} = 'Male'...
S.J.Chapman《MATLAB编程》中文版修正版_部分3_信息与通信_工程科技_专业资料。...Stephen J.Chapman《MAT... 39页 免费 Stephen J.Chapman《MAT... 37页 免...
热门文档