2 Star 12 Fork 2

Banana / interesting_Matlab

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_calendar.asv 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
tridu33 提交于 2018-09-21 20:04 . 一波大更新
function test_calendar(year,month)
% 输入年份,月份,打印这个月的月历
run = 0;
ping = 0;
fprintf('\n%s %s %s %s %s %s %s\n',...
'日','一','二','三','四','五','六');
% 计算从第一年到前一年的闰年和平年的个数
for i =1:year-1
if (mod(i,4)==0 & mod(i,100)~=0) | mod(i,400)==0
run = run+1;
else
ping = ping+1;
end
end
% 计算从第一年到当年前一个月的天数
sum = 366*run+365*ping;
for i = 1:month-1
sum = sum+monthday(year,i);
end
% 获得这个月的天数
n = monthday(year,month);
temp = zeros(n,1);
sum = sum+1;
% 计算这个月第一天是星期几
wkd = mod(sum,7);
for i = 1:n
temp(wkd+i) = i;
end
l = 1;
m = 1;
% 打印日历
for i = 1:length(temp)
if temp(i) ==0
temp2(l,m) = ' ';
fprintf(' ');
m = m+1;
else
temp2(l,m) = temp(i);
if temp(i) >= 10
fprintf('%d ',temp(i));
else
fprintf('%d ',temp(i));
end
m = m+1;
end
if mod(i,7)==0
fprintf('\n');
m = 1;
l = l+1;
end
end
fprintf('\n');
% 闰年和平年每月的天数
function out = monthday(year,i)
if mod(year,4)==0 & mod(year,100)~=0 | mod(year,400)==0
data = [31 29 31 30 31 30 31 31 30 31 30 31];
else
data = [31 28 31 30 31 30 31 31 30 31 30 31];
end
out = data(i);
Matlab
1
https://gitee.com/YuHui_Zhang/interesting_Matlab.git
git@gitee.com:YuHui_Zhang/interesting_Matlab.git
YuHui_Zhang
interesting_Matlab
interesting_Matlab
master

搜索帮助