Hourly averages over a 20yr time series

4 views (last 30 days)
Ross O'Connell
Ross O'Connell on 10 Mar 2021
Commented: Ross O'Connell on 11 Mar 2021
Hi,
I have a 20yr time series of data with time values for each hour, so ~175,000 time values. I want to calculate an hourly mean for the time series, so for example on Jan 1st at 00:00:00, I will have 20 values at this time over the 20 year series and I would like to calculate the mean, and so on for each date and time. The date and time values are formatted as '01-Jan-2000 00:00:00'.
  2 Comments
Steven Lord
Steven Lord on 10 Mar 2021
To clarify, the first "bin" of your data would take the mean of data from the following dates and times in your time series?
dt = datetime(2000:2020, 1, 1, 0, 0, 0, 'Format', 'dd-MMM-yyyy HH:mm:ss')
dt = 1×21 datetime array
01-Jan-2000 00:00:00 01-Jan-2001 00:00:00 01-Jan-2002 00:00:00 01-Jan-2003 00:00:00 01-Jan-2004 00:00:00 01-Jan-2005 00:00:00 01-Jan-2006 00:00:00 01-Jan-2007 00:00:00 01-Jan-2008 00:00:00 01-Jan-2009 00:00:00 01-Jan-2010 00:00:00 01-Jan-2011 00:00:00 01-Jan-2012 00:00:00 01-Jan-2013 00:00:00 01-Jan-2014 00:00:00 01-Jan-2015 00:00:00 01-Jan-2016 00:00:00 01-Jan-2017 00:00:00 01-Jan-2018 00:00:00 01-Jan-2019 00:00:00 01-Jan-2020 00:00:00
And the next bin would have data from:
dt = datetime(2000:2020, 1, 1, 1, 0, 0)
dt = 1×21 datetime array
01-Jan-2000 01:00:00 01-Jan-2001 01:00:00 01-Jan-2002 01:00:00 01-Jan-2003 01:00:00 01-Jan-2004 01:00:00 01-Jan-2005 01:00:00 01-Jan-2006 01:00:00 01-Jan-2007 01:00:00 01-Jan-2008 01:00:00 01-Jan-2009 01:00:00 01-Jan-2010 01:00:00 01-Jan-2011 01:00:00 01-Jan-2012 01:00:00 01-Jan-2013 01:00:00 01-Jan-2014 01:00:00 01-Jan-2015 01:00:00 01-Jan-2016 01:00:00 01-Jan-2017 01:00:00 01-Jan-2018 01:00:00 01-Jan-2019 01:00:00 01-Jan-2020 01:00:00
and so on and so forth?
Ross O'Connell
Ross O'Connell on 11 Mar 2021
Hi Steven,
Yes this is exactly how I want to add the data to the 'bins'.
I should have clarified further, the data is actually NetCDF, so the array for my variable is 21x11x175296 (so latitudexlongitudextime) and my time array is just 1 x 175296.
I found the following code from a previous query that I think was carrying out the same thing, but When I try to compute Y I am getting the following error:
Error using splitapply (line 99)
The data variables must have the same number of rows as the vector of group numbers. The group number vector has
175296 row(s), and data variable 1 has 21 row(s).
(https://uk.mathworks.com/matlabcentral/answers/506409-average-values-from-timeseries):
Day = day(Date,'dayofyear');
Hour = hour(UTtime);
[G,dayID,hourID]=findgroups(Day,Hour); % Added 3rd output
Y = splitapply(@mean,Temperature,G);

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 10 Mar 2021
See if the groupsummary function will do what you want. The retime function is also an option.

Sargondjani
Sargondjani on 10 Mar 2021
Its not exactly clear over which values you want to calculate the mean, but have a look at this function, that can calculate moving averages:
https://uk.mathworks.com/help/matlab/ref/movmean.html

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!