필터 지우기
필터 지우기

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)??

조회 수: 1 (최근 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
Nan Shen
Nan Shen 2012년 1월 27일
Thanks very much, it works perfect and get me learnt things.
Leah
Leah 2012년 1월 27일
Glad to help, I do lots of time series analysis.

댓글을 달려면 로그인하십시오.


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