given two dates (1/1/2012, 12/1/2012), how to have an array of months (1/1/2011,​2/1/2011,.​..,12/1/20​12)??

2 次查看(过去 30 天)
given two dates (1/1/2012, 12/1/2012), how to have an array of months between the two dates[1/1/2011,2/1/2011,...,12/1/2012]??

回答(2 个)

Leah
Leah 2012-1-27
something like this maybe
dv=datenum('1/1/2012'): datenum('12/1/2012');
dv=datevec(dv);
dv=datenum(dv(dv(:,3)==1,:)); %only take dates where day==1
datestr(ans)
  3 个评论

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-1-27
nummon = 12; %stats for 12 conseq months
monstarts = datenum( [2012*ones(nummon,1), (1:nummon).',
ones(nummon,1)]);
The above would be in serial date format. You can use datestr() to convert to printable dates.

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by