Effacer les filtres
Effacer les filtres

Open and read monthly dataseries with the filename 'yyyymmdd'

2 vues (au cours des 30 derniers jours)
Agnete
Agnete le 26 Nov 2013
Modifié(e) : dpb le 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');
.....

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 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];

Plus de réponses (1)

dpb
dpb le 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 commentaires
Agnete
Agnete le 27 Nov 2013
Modifié(e) : Agnete le 27 Nov 2013
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 le 27 Nov 2013
Modifié(e) : dpb le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Time Series Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by