필터 지우기
필터 지우기

Conversion from daily to monthly frequency

조회 수: 3 (최근 30일)
kanimbla
kanimbla 2014년 6월 8일
댓글: kanimbla 2014년 6월 8일
Hi,
I have a time series - daily frequency - stored in a vector X. In addition, I have a vector T containing the corresponding date strings of this time series.
Based on X, I would like to generate a time series Z with monthly frequency. For instance, I would like to generate Z using the values asscociated with the last calendar day of each month.
Your help is very much appreciated!
kanimbla

답변 (2개)

Star Strider
Star Strider 2014년 6월 8일
The eomday function is just waiting for you to discover it!

dpb
dpb 2014년 6월 8일
First idea -- create the datenum() vector of the time series and then the EOM (end-of-month) days for the year(s) included within. Then return those matching.
To create the EOM day vector
dn=datenum(yourtsdates); % full array datenum vector
[y,~]=datevec([dn(1) dn(end)]).'; % the years in the series
y=unique(y); % and eliminate duplicate if only one year
yy=repmat(y,1,12).'; yy=yy(:); % each year for each 12 months/year
dneom=datenum(yy,repmat([1:12].',length(y),1), ...
cell2mat(arrayfun(@(yr) eomday(yr, [1:12].'),y, ...
'uniformoutput',false)));
The last looks more complicated than it really is... :)
It computes the datenum for the eom days for each month of the years found in the timeseries (y). To match up the array sizes, it duplicates the months for that many years and then calls eomday for each year to build the array of days to go along with the year and month. This will automagically handle leap years, etc., ...
Then just find these positions in the overall date number vector.
  댓글 수: 1
kanimbla
kanimbla 2014년 6월 8일
Thanks a lot for your elaboration!
Finally, I adopted and slightly modified the procedure suggested here:
Best regards

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by