Averaging hour value of a timetable

9 visualizzazioni (ultimi 30 giorni)
Hammad Khan
Hammad Khan il 16 Feb 2020
Commentato: Steven Lord il 25 Set 2020
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

Risposte (1)

Akira Agata
Akira Agata il 17 Feb 2020
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 Commenti
Eric Beamesderfer
Eric Beamesderfer il 25 Set 2020
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 il 25 Set 2020
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.

Accedi per commentare.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by