Average of variables in timetable belonging to the same day over several years
조회 수: 12 (최근 30일)
이전 댓글 표시
Hello, I have a timetable, TT(681-by-19), with unevenly spaced daily data from 2010 to 2020 and 19 variables (there might be days that do not occur every year in addition to gaps where entire months are missing). I want to calculate the mean of the variables that correspond to the same day throughout the different years. For example I want to calculate the mean of each of the 19 variables that correspond to 25-oct 2010, 25-oct 2011, ..., 25-oct 2020 and so on for the different dates. That way I would have each unique day-month occurring only once in the output.
Note: I also have the dates seperately as a datetime array and as a numeric array in the form of yyyymmdd (681-by-1) and the 19 variables in a numeric array (681-by-19), if there is a simpler method without the use of the timetable.
Thanks for any assistance.
댓글 수: 0
채택된 답변
Peter Perkins
2022년 8월 25일
Ziad, it seems that "dayofyear" is using "serial day number of year", and as you found, is lumping 29-Feb's with the non-leap 1-Mar's, etc. What you want is to group by month/day. If you use the month and day of month as grouping vars, you get what you want:
dt = [datetime(2012,2,27:31) ...
datetime(2013,2,27:30) ...
datetime(2014,2,27:30) ...
datetime(2015,2,27:30) ...
datetime(2016,2,27:31)]';
x = dt.Day;
tt = timetable(x,RowTimes=dt)
tt.Month = string(month(tt.Time,"name"));
tt.Day = day(tt.Time,"dayofmonth");
means = groupsummary(tt,["Month" "Day"],"mean","x")
추가 답변 (1개)
참고 항목
카테고리
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!