# Hourly averages over a 20yr time series

12 views (last 30 days)
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 CommentsShowHide 1 older comment
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).
Day = day(Date,'dayofyear');
Hour = hour(UTtime);
Y = splitapply(@mean,Temperature,G);

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

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

R2018a

### Community Treasure Hunt

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

Start Hunting!