MATLAB Answers

Monthly Average from Daily Data

8 views (last 30 days)
Lauren Fennelly
Lauren Fennelly on 6 May 2020
Answered: Akira Agata on 7 May 2020
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.

  0 Comments

Sign in to comment.

Answers (2)

Sindar
Sindar on 6 May 2020
Edited: Sindar on 6 May 2020
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)

  0 Comments

Sign in to comment.


Akira Agata
Akira Agata on 7 May 2020
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

  0 Comments

Sign in to comment.