Averaging hour value of a timetable

8 次查看(过去 30 天)
I am new to MatLAB and wanted help. I have hourly precipitation data of a certain place for 30 years (total values/rows=30*365*24=262800). Is there any way i can average values of each hour and generate a new vector having only 12 rows? In other words average of every value located 8640 rows apart.Thanks

回答(1 个)

Akira Agata
Akira Agata 2020-2-17
How about the following solution?
% Create sample timetable
Time = datetime(2019,1,1,0,0,0) + hours(0:239)';
Value = rand(240,1);
TT = timetable(Time,Value);
% Calculate average value for each hour
[Group, Hour] = findgroups(TT.Time.Hour);
AvgValue = splitapply(@mean, TT.Value, Group);
tResult = table(Hour,AvgValue);
The result will be like this:
>> tResult
tResult =
24×2 table
Hour AvgValue
____ ________
0 0.61649
1 0.51445
2 0.32941
3 0.60418
4 0.53319
5 0.39934
6 0.41297
7 0.42935
8 0.48803
9 0.50767
10 0.55387
11 0.49949
12 0.59754
13 0.43441
14 0.40604
15 0.40547
16 0.37117
17 0.4985
18 0.5161
19 0.52695
20 0.2493
21 0.66763
22 0.57555
23 0.69638
  4 个评论
Eric Beamesderfer
Eric Beamesderfer 2020-9-25
atmosfera - I had a similar question. I am looking at a full year of data and trust my timeseries (don't need a solution involving a timetable), so here's what I ultimately did for half-hour data (non-leap year):
Steven Lord
Steven Lord 2020-9-25
Use retime with a NEWTIMES input spaced at half an hour intervals and an aggregation method of 'mean'.
newtimes = datetime('now') + hours(0:0.5:6);
If you're doing this outside the context of a timetable, use timeofday to get the elapsed time since midnight and discretize that duration array using a vector of edges created using hours like I did above.

请先登录,再进行评论。

类别

Help CenterFile 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