Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

eomday extension for wrapping month numbers

Asked by Walter Roberson

Walter Roberson (view profile)

on 24 Apr 2012

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;


Walter Roberson

Walter Roberson (view profile)


1 Answer

Answer by Leah

Leah (view profile)

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

countdays=eomday(dv(:,1), dv(:,2));



Leah (view profile)

Contact us