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