필터 지우기
필터 지우기

Open and read monthly dataseries with the filename 'yyyymmdd'

조회 수: 2 (최근 30일)
Agnete
Agnete 2013년 11월 26일
편집: dpb 2013년 11월 27일
How do I make my a variable count only months instead of each day?
StartDate1 = num2str(StartDate); %date to string
StartDate2=datenum(StartDate1,'yyyymmdd'); %date to serial date number
EndDate1 = num2str(EndDate);
EndDate2=datenum(EndDate1,'yyyymmdd');
Dates=[StartDate2:EndDate2];
startvecs = datevec(StartDate2);
endvecs = datevec(EndDate2);
diffvecs = endvecs - startvecs;
countmonths = 12*diffvecs(:,1) + diffvecs(:,2)+1;
NumOfDates=max(size(Dates));
day = 1;
day = num2str(day);
day=strcat('0',day);
for i = 1:countmonths %looping through months
Date = datestr(Dates(i),'yyyymm');
year = Date(1:4);
month = Date(5:6);
filename = strcat(ProcessingPath,'3B43.',year,month,day,'.7A.HDF');
.....

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 11월 27일
Try this is code:
StartDate = 20100502;
EndDate = 20160201;
v = datevec([sprintf('%d',StartDate);sprintf('%d',EndDate)],'yyyymmdd');
[y,m,d] =datevec(datenum(v(1,1),v(1,2)+(0:diff(v(:,1:2))*[12;1])',1));
out = [y,m,d];

추가 답변 (1개)

dpb
dpb 2013년 11월 26일
[y,m,d]=datevec(StartDate2);
nmo=round(EndDate2-StartDate2)/12)+1; % num months approx between
Dates=[StartDate2:datenum(y,m+[1:nmo]',d,0,0,0):EndDate2]; % datenums between for mo on that day
Salt to suit...
  댓글 수: 2
Agnete
Agnete 2013년 11월 27일
편집: Agnete 2013년 11월 27일
Thanks, it gave new ideas but I am still not there.
The 'nmo' does not gives the right number of months (a factor 3 wrong)
The 'Dates' is not a vector but just the the first date.
In my script 'Dates' is the a vector of the numerical dates between start and end date. It should be something like 'Dates' are be made into a vector only containing 2005 01 01, 2005 02 01 etc (in serial date number) and that I do not count 'dd' but 'mm' for each loop.
dpb
dpb 2013년 11월 27일
편집: dpb 2013년 11월 27일
Don't see where the nmo should be off...works here for sample date ranges.
Sorry about the Dates vector, I mixed horses in midstream and forgot to unsaddle the first--
The vector would be
Dates=datenum(y,m+[0:nmo]',d,0,0,0);
I started w/ building a delta then realized the month vector could be folded into the expression then didn't remove the [start:delta:end] form. Fortunately Andrei posted the same basic answer.

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

카테고리

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