MATLAB: Daily average precip for many years

mean daily precip values

I have a large matrix of two columns containing dates (eg 1/1/1991) and precip values. I want to create the average daily precip for all years from 1991-2016 such that the day of the year is in column 1 and the ave precip value is in column 2. I'm getting bogged down I believe because of leap years (not sure how to eliminate that date, which is fine). Any help would be greatly appreciated.

Best Answer

Just taking a stab presuming the file is something recognizable--
precip=table2timetable(readtable('yourfile.ext')); % read the file; convert to timetable
daily=retime(precip,'daily','mean');
Done!
"Here is the precip file..."
Oh...only daily data and already in table--OK, then create the grouping variable
>> precip.DOM=day(precip.DATE); % day of month each entry
>>daily=varfun(@mean,precip,'groupingvariables','DOM','inputvariables','Precipitation');
...
ADDENDUM OK, answer the question asked... :)
>> precip.DOY=day(precip.DATE,'dayofyear');
>> daily=varfun(@mean,precip,'groupingvariables','DOY','inputvariables','Precipitation');
>> whos daily
Name Size Bytes Class Attributes
daily 366x3 10149 table
>> daily(1:10,:)
ans =
10×3 table
DOY GroupCount mean_Precipitation
___ __________ __________________
1 26 3.27692307692308
2 26 3.8
3 26 2.5
4 26 2.84230769230769
5 26 3.94615384615385
6 26 5.21923076923077
7 26 2.13461538461539
8 26 2.53461538461538
9 26 3.65
10 26 3.33461538461538
>>
should work; I believe the 'dayofyear' option came about R2104 or so...there's just too much stuff to try to recall introduced too rapidly.