eomday extension for wrapping month numbers

1 次查看(过去 30 天)
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;

采纳的回答

Leah
Leah 2012-5-2
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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Array Geometries and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by