Averaging value in table grouping by some datetime

URGENT
I Have a table done like this
Date Value
31/12/2015 23:00:00 3
31/12/2015 23:10:00 4
31/12/2015 23:20:00 5
31/12/2015 23:30:00 6
31/12/2015 23:40:00 7
31/12/2015 23:50:00 8
so the dataset contain data taking every 10 minutes during the year 2015 i want to make the mean hourly i.e averaging all value of an hour for instance i want result like this 31/12/2015 23:00:00 where in this case 23:00:00 raprresent the average of all the value taking every 10'
Thanks in advance

1 个评论

I resolve it like this
% shift the the date toward the start of the hour 23:00:00
dataset.Date = dateshift(dataset.Date, 'end', 'start');
% taking the average groupping by Date
result = grpstats(dataset, 'Date')

请先登录,再进行评论。

回答(1 个)

Use groupsummary. If your original table is called tbl, the following would work.
meanTbl = groupsummary(tbl,"Date","hour","mean","Value")

类别

在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by