フィルターのクリア

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 Center および File ExchangeTime Series Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by