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

1 visualización (últimos 30 días)
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 comentarios
Jakub
Jakub el 1 de En. de 2023
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 el 1 de En. de 2023
Editada: John D'Errico el 1 de En. de 2023
@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?

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 1 de En. de 2023
Editada: Star Strider el 1 de En. de 2023
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.
.

Más respuestas (0)

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by