good morning. I have a matrix (eout) with 14610 rows and 16 column. 14610 row represent one of each day of the period between 01-01-1960 and 31-12-2000.
What I need is a new matrix with 40 rows and 16 columns with a mean for each year. something like a mean of 365 rows continuously. The problem I have are the leap years each 4 years.
Suggestions to solve this?
For a start, to get the number of days for a given year:
function n = ndays(year)
tmp = repmat([1,1,0,0,0],numel(year),1);
n = datenum([year(:)+1,tmp])-datenum([year(:), tmp]);
end
With this, you could collect the rows e.g. with mat2cell
:
rows_per_year = ndays(1960:2000);
chunks = mat2cell(yourInputMatrix, rows_per_year, size(yourInputMatrix,2));
means = cellfun(@(x) mean(x,1), chunks);
(The latter part comes untested..)