Produce a Date vector starting with a desired date

조회 수: 6 (최근 30일)
Pedro Cavaco
Pedro Cavaco 2011년 5월 10일
Hi all,
I want to generate a date vector that starts at, say '01-Jan-2001 00:00:00' and skips by hour all the way up to '31-Dec-2031 23:00:00'.
I tried this:
Date = datevec('01-Jan-2011 00:00:00','dd-mmm-yyyy hh:mm:ss',
'31-12-2031 23:00:00');
But I don't think that's the way.
Any suggestions??
Any attempt to help is appreciated,
Pedro Cavaco

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 10일
a = datenum({'01-Jan-2011 00:00:00';'31-Dec-2031 23:00:00'});
Out = datevec(a(1):1/24:a(2));
  댓글 수: 7
Andrei Bobrov
Andrei Bobrov 2011년 5월 10일
very large thank you Teja , again my typo ... corrected
Oleg Komarov
Oleg Komarov 2011년 5월 10일
My version had a small bug (nevertheless it did differentiate between 30,31 and lap years) but Andrei's version is really the best.
To convert to strings (takes time):
datestr(Out,0)
+1

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by