binary vector that consists of a zero for normal years and a 1 for a leap year

조회 수: 1 (최근 30일)
I need to create a vector that consists of a binary vector that consists of a zero for normal years and a 1 for a leap year, with some data i already have. How would i do this?
  댓글 수: 4
Jakub
Jakub 2023년 1월 1일
ive already completed that 2 hour training. i know what vectors are and how to create them but i dont know how to implement it into the data set of 9000 days.
John D'Errico
John D'Errico 2023년 1월 1일
편집: John D'Errico 2023년 1월 1일
@Jakub Reemmber that we don't know at all what skills you have. But when you ask a question that seems simple, we must assume you know nothing about MATLAB.
Do you know how to compute the year, for each date?
Do you know the formula to identify a leap year, given the numbered year? How would you use that with the mod function, for example, to identify leap years?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2023년 1월 1일
편집: Star Strider 2023년 1월 1일
Use the eomday function —
YearVct = 1950:2050;
Lv = eomday(YearVct,2) == 29 % Create Logical Vector
Lv = 1×101 logical array
0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0
LeapYears = YearVct(Lv) % Leap Years
LeapYears = 1×25
1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 2004 2008 2012 2016 2020 2024 2028 2032 2036 2040 2044 2048
LeapYearsMtx = buffer(LeapYears,5)
LeapYearsMtx = 5×5
1952 1972 1992 2012 2032 1956 1976 1996 2016 2036 1960 1980 2000 2020 2040 1964 1984 2004 2024 2044 1968 1988 2008 2028 2048
EDIT — (1 Jan 2023 at 17:15)
This is based on the eomday Find Leap Years documentation section.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by