getting 'mondays' that are first day of the month without using datenum
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm trying to get the number of mondays that are first day of the month in a year without using the inbuilt function datenum. Any hint on how to tackle this ? thanks
댓글 수: 0
채택된 답변
Star Strider
2016년 6월 22일
편집: Star Strider
2016년 6월 22일
That’s probably not possible. The weekday function implicitly uses datenum.
EDIT — However, if you choose to ignore that minor problem:
Year = 2016;
Month = 1:12;
ds = regexp(sprintf('%4d/%02d/%02d\n', [repmat(Year, size(Month))' Month' ones(size(Month'))]'), '\n', 'split');
for k1 = 1:length(Month)
FirstDay(k1) = weekday(ds(k1));
end
FirstDayMonday = Month(FirstDay == 2)
FirstDayMonday =
2 8
So, in 2016, February and August begin on Mondays.
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!