フィルターのクリア

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 Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by