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 件のコメント
fred ssemwogerere
2020 年 2 月 16 日
Hello, please refer to the link below. It should be of great help.
回答 (1 件)
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
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
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 Center および File Exchange で Dates and Time についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!