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;
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Array Geometries and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!