# How to average data per hour ?

28 views (last 30 days)
Dharmesh Joshi on 14 May 2022
Commented: Star Strider on 15 May 2022
Hi
I have sensor data which is stored once a minute or at times maybe few times a minute . This is an example of the timestamps data array.
Columns 28216 through 28220
18-Apr-2022 07:14:14 18-Apr-2022 07:13:12 18-Apr-2022 07:12:09 18-Apr-2022 07:11:06 18-Apr-2022 07:10:04
Columns 28221 through 28225
18-Apr-2022 07:09:02 18-Apr-2022 07:08:01 18-Apr-2022 07:06:59 18-Apr-2022 07:05:58 18-Apr-2022 07:04:56
And this would be the sensour output
Columns 18,853 through 18,864
45.9099 48.7762 43.0352 48.7727 37.2945 37.2908 43.0245 45.8932 34.4159 28.6791 37.2786 28.6746
Columns 18,865 through 18,876
40.1419 37.2736 34.4061 57.3400 71.6705 83.1326 45.8650 45.8606 77.3876 65.9187 68.7805 54.4469
How can i preform an hourly average of my data, so that the times stamp as similar to the following:
18-Apr-2022 07:00:00 18-Apr-2022 08:00:00 18-Apr-2022 09:00:00
And the corresponding data mean is also outputted for eac hours time stamp?

Star Strider on 14 May 2022
Edited: Star Strider on 14 May 2022
Transpose it so that the columns are rows, create it as a timetable and then use the retime function specifying 'hourly','mean'.
t = datetime({'18-Apr-2022 07:14:14' '18-Apr-2022 07:13:12' '18-Apr-2022 07:12:09' '18-Apr-2022 07:11:06' '18-Apr-2022 07:10:04' '18-Apr-2022 07:09:02' '18-Apr-2022 07:08:01' '18-Apr-2022 07:06:59' '18-Apr-2022 07:05:58' '18-Apr-2022 07:04:56'})';
s = [45.9099 48.7762 43.0352 48.7727 37.2945 37.2908 43.0245 45.8932 34.4159 28.6791].';
TT1 = timetable(t,s)
TT1 = 10×1 timetable
t s ____________________ ______ 18-Apr-2022 07:14:14 45.91 18-Apr-2022 07:13:12 48.776 18-Apr-2022 07:12:09 43.035 18-Apr-2022 07:11:06 48.773 18-Apr-2022 07:10:04 37.294 18-Apr-2022 07:09:02 37.291 18-Apr-2022 07:08:01 43.025 18-Apr-2022 07:06:59 45.893 18-Apr-2022 07:05:58 34.416 18-Apr-2022 07:04:56 28.679
TT1r = retime(TT1,'hourly','mean')
TT1r = timetable
t s ____________________ ______ 18-Apr-2022 07:00:00 41.309
EDIT — (14 May 2022 at 21:32)
.
##### 2 CommentsShowHide 1 older comment
Star Strider on 15 May 2022
As always, my pleasure!
For different intervals, see the documentation seciton on Interpolate Timetable Data to Time Vector.
.

### Categories

Find more on Timetables in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by