how can create date string for 360 days like this yyyymmdd ?

조회 수: 1 (최근 30일)
varunesh
varunesh 2017년 5월 11일
댓글: Rik 2017년 5월 11일
hello every one, how can create date string for 2005/12/01 to 2045/11/30 if each year include 360 days and each months include 30 days. I am trying from this
date =datestr(datenum('2005/12/01'):datenum('2045/11/30'),'yyyymmdd');
but unable to get right answer. This is giving 365 and 366 days in year. Thank you so much in advance.
  댓글 수: 2
KL
KL 2017년 5월 11일
30 days even for february?
varunesh
varunesh 2017년 5월 11일
yes 30 days for feb also.

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

답변 (1개)

KL
KL 2017년 5월 11일
편집: KL 2017년 5월 11일
ny = 3; %number of years
sy = 2005; %start year
y = sy:sy+ny;
FD = [];
for i = 1:ny
daysOfYear = [num2str(repmat(y(i),360,1))...
num2str(reshape(repmat(1:12,30,1),360,1))...
num2str(reshape(repmat(1:30,12,1)',360,1))];
daysOfYear(daysOfYear==' ')='0';
FD = [FD; daysOfYear];
end
  댓글 수: 1
Rik
Rik 2017년 5월 11일
You can also use sprintf. That way you can avoid filling a variable in a loop.

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

카테고리

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