Loop through a matrix

2 次查看(过去 30 天)
Damith
Damith 2014-4-30
评论: dpb 2014-4-30
hi,
I have a 3652500 x 2 matrix. That is reprsenting days of the years from 3000 to 12999 years (total 10000 years of data) of data . Once every 4 years there will be a leap year (i.e. 366 days). So I need to arrange yearly data like this [365 x 10000]. Can somebody help me with this?
Thanks.
  2 个评论
Roger Stafford
Roger Stafford 2014-4-30
You seem to be forgetting that we use the Gregorian calendar. Here is a paragraph from a Wikipedia article on the subject: "Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is."
dpb
dpb 2014-4-30
This sounds (other than the English) suspiciously like an earlier posting but you may find the isLeapYear logic function I provided earlier of use if not...
isLeapYear=(eomday(Y,2)==29); % logical vector T for Y==leap year
To use, build a year vector Y to go along with your daily data as
Y = [datenum(3000,1,1):datenum(12999,12,31)]';
The above does presume the Matlab datenum functions are ok for such extended ranges; I've not looked to see if they document the upper bound or not.
You can with the result of the above simply reshape the leap year years w/ 365 day/yr and obviously the logical negation of the result will provide the years w/ 366 day/yr.

请先登录,再进行评论。

回答(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