Conversion from daily to monthly frequency
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (2)
dpb
el 8 de Jun. de 2014
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.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!