Open and read monthly dataseries with the filename 'yyyymmdd'
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Andrei Bobrov
on 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];
More Answers (1)
dpb
on 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 Comments
dpb
on 27 Nov 2013
Edited: dpb
on 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.
See Also
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!