Open and read monthly dataseries with the filename 'yyyymmdd'
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Agnete
am 26 Nov. 2013
Bearbeitet: dpb
am 27 Nov. 2013
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');
.....
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 27 Nov. 2013
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];
Weitere Antworten (1)
dpb
am 26 Nov. 2013
[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 Kommentare
dpb
am 27 Nov. 2013
Bearbeitet: dpb
am 27 Nov. 2013
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.
Siehe auch
Kategorien
Mehr zu Time Series Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!