Calculate average for each hour in day
Show older comments
I have a bunch of data in datetime format similar to this:
2010-Nov-30 18:00.00 0 8.7 17.05 61.38
I have summed all the data into hours, but I would like to calculate the average at every hour 00:00, 01:00, 02:00... 23:00 for every day in the year.
I have data for a whole year, so I'm interested in seeing the average values in a day, per hour, with the data from the whole year.
I've tried to use retime but I can't really get it to function correctly. Maybe it's the wrong function for this purpose.
3 Comments
Adam Danz
on 20 Jun 2020
retime is definitely the way to go. Why didn't it work for you?
Oliver Zacho
on 20 Jun 2020
Adam Danz
on 20 Jun 2020
Could you show us what you tried and describe the input variables used? It will be easier to help you tweek that instead of creating a different example out of our imaginations that may not even be suitable with your data.
Accepted Answer
More Answers (1)
Catriona Fyffe
on 22 Jul 2020
A very simple way to solve this if you have whole days starting at 00:00 is to use reshape. Its a bit old school but I like it! However I have come onto this page to solve this problem for data which doesn't start at 00:00 (not my choice!)
NHours=size(VarA,1);
NDays=NHours/24;
VarA_AH=nanmean(reshape(VarA,[24,NDays]),2);
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!