eomday extension for wrapping month numbers

1 view (last 30 days)
eomday() does not handle situations where the month number is greater than 12, such as
eomday(2012, 3:15)
to mean March 2012 through March 2013. The user cannot use something like,
eomday([2012, 2013], {3:12, 1:3})
as eomday does not handle cell arrays and eomdays requires that either at least one argument be a scalar or else that the number of years matches the number of months.
This situation is not fatal, but it can be inconvenient.
I therefore propose an extension to eomday() to handle month wrap-arounds. My extension code still requires that one or both arguments be scalars, but provides a bit more convenience.
The code change is the last few days of eomday, and replaces the last 2 lines of code with
madj = 1+mod(m-1,12);
yadj = y + floor((m-1)/12);
d(:) = dpm(madj);
d((madj == 2) & ((rem(yadj,4) == 0 & rem(yadj,100) ~= 0) | rem(yadj,400) == 0)) = 29;

Accepted Answer

Leah
Leah on 2 May 2012
eomday([2012, 2013], {3:12, 1:3})
would work like this
eomday([repmat(2012,1,10) repmat(2013,1,3)], [3:12 1:3])
Use datevec on time series data then use the month year vectors in eomday when I'm converting to average daily
dates=datenum('1/1/2010'):datenum(date());
dv=datevec(dates);
countdays=eomday(dv(:,1), dv(:,2));

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!