Monthly Average from Daily Data

조회 수: 12 (최근 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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by