⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5-13.m

📁 《MATLAB 7.0编程基础》第5章 (源码实例)主要讲解MATLAB的编程基础
💻 M
字号:
%Define variable
%day --Day(dd)
%day_of_year  --Day of year
%ii         --Loop index     
%month      --Month(mm)
%year       --Year(yyyy)
%Get day, month, and year to convert
disp('Ihis 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;% 可被400整除的是闰年
elseif mod(year,100)==0
    leap_day=1%虽然被100整除但不是闰年
elseif mod(year,4)==0
    leap_day=1%被4整除的是闰年
else
    leap_day=0 %其它的不是闰年
end
%calculate day of year by adding current day to month
%dya in previous month
day_of_year=day;
for ii=1:month-1%将天数加入1月到12月
    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
 fprint('The date %2d/%2d%2d%4d is day of year %d.\n',....
     month,day, year, day_of_year);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -