Timetable Monthly Average over Many Years
조회 수: 37 (최근 30일)
이전 댓글 표시
I have a daily precipitation data file with two columns.The first column is "date", with date format yyyy-mm-dd and the second column is "precip" with double format. My data ranges from 1980-01-01 to 2010-12-31, and I would like to determine the average precipitation values for each month over that interval.
Example of desired result:
Month avgPrecip
Jan 0.0056
Feb 0.0034
...
for each month.
I have attached my csv file with the data and my current progess. I can get the monthly average of the data within each year using a timetable and retime, but I am stuck trying to average the monthly average data for the entire data range. Thank you!
precip = readtable('CR_precip.csv');
precip = table2timetable(precip);
monthlyAvg = retime(precip,'monthly','mean');
댓글 수: 0
채택된 답변
Guillaume
2019년 10월 2일
The easiest:
precip = table2timetable(readtable('CR_precip.csv'));
monthlyavg = groupsummary(precip, 'day', 'monthofyear', 'mean')
댓글 수: 3
Ritesh
2023년 5월 4일
편집: Ritesh
2023년 5월 4일
with this code I am getting follwing error:
Error using matlab.internal.math.checkDataVariables (line 59)
Invalid grouping variables.
Error in matlab.internal.math.parseGroupVars (line 14)
[groupVars,T] = matlab.internal.math.checkDataVariables(T,groupVars,messageIdent,'Group');
Error in groupsummary (line 172)
[groupingData,groupVars] = matlab.internal.math.parseGroupVars(groupVars,tableFlag,'groupsummary',T);
Manoj Kumar
2023년 6월 26일
Please take a look at the variables used in the CR_precip.csv file. The time/date in the timetable is defined as 'day'. If you make the call based on this, the function call should work. I hope this helps
추가 답변 (2개)
QuanCCC
2019년 10월 2일
you can simply make another column of year-month-day-time, merge it to your data. Then transform it to timetable, time column will be your new column. Then use the same 'monthly','mean' on all months.
t1 = datetime(1980,01,01,12,0,0);
t2 = datetime(2010,12,31,12,0,0);
t = t1:t2;
t = t';
clear t1 t2
NewData = timetable(t, YourOldData); % merge data
MonthlyAve = retime(NewData, 'monthly', 'mean');
댓글 수: 0
Akira Agata
2019년 10월 3일
Looking at your csv data, some additional options will be needed.
(1) To specify the delimiter in your csv data, 'Delimiter' option should be added in readtabe function
(2) 'Format' option should be added in datetime function
The following is an example:
T = readtable('CR_precip.csv','Delimiter',',');
T.day = datetime(T.day,'Format','MM/dd/yyyy');
TT = table2timetable(T);
TT = retime(TT,'monthly','mean');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Timetables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!