Monthly Average from Daily Data

9 ビュー (過去 30 日間)
Lauren Fennelly
Lauren Fennelly 2020 年 5 月 6 日
回答済み: Akira Agata 2020 年 5 月 7 日
I hava daily weather dataset and I need the montly average. However, I need the average of a user input. For example when prompted to enter a month 'Jan' It will display the average temperature for January.

回答 (2 件)

Sindar
Sindar 2020 年 5 月 6 日
編集済み: Sindar 2020 年 5 月 6 日
See findgroups for taking the mean based on a grouping variable.
See month for converting a datetime variable to its month
See startsWith to identify a month based on a leading string (hint: their input is the pattern)

Akira Agata
Akira Agata 2020 年 5 月 7 日
Another way is to use groupsummary function.
The following is an example (note that the follwing returns average value with nanflag = 'omitnan').
T = readtable('BTVHistoricData (3).csv');
T.DATE = datetime(T.DATE,'InputFormat','yyyy-MM');
T.Month = T.DATE.Month;
Tavg = groupsummary(T(:,4:end),'Month','mean');
>> Tavg
Tavg =
12×6 table
Month GroupCount mean_AWND mean_DT32 mean_SNOW mean_TAVG
_____ __________ _________ _________ _________ _________
1 77 9.1973 29.442 19.727 18.327
2 76 8.6639 26.737 17.357 20.039
3 76 8.8861 26.197 14.132 30.342
4 76 8.9306 14.25 3.8382 43.763
5 76 8.2361 2.1711 0.11081 56.23
6 77 7.6611 0 0 65.603
7 77 7.0611 0 0 70.521
8 77 6.9194 0 0 68.462
9 77 7.4333 0.58442 0.0013889 60.208
10 77 8.1111 7.6753 0.25342 48.691
11 77 9.0472 18.156 6.4896 37.508
12 77 8.9167 27.61 18.648 24.647

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by