早上好。我有一个 14610 行和 16 列的矩阵(eout)。14610 行表示 1960 年 1 月 1 日至 2000 年 12 月 31 日期间的每一天。
我需要的是一个新的 40 行 16 列的矩阵,每年的平均值。类似于连续 365 行的平均值。我遇到的问题是每 4 年闰年。
解决这个问题的建议?
首先,获取给定年份的天数:
function n = ndays(year)
tmp = repmat([1,1,0,0,0],numel(year),1);
n = datenum([year(:)+1,tmp])-datenum([year(:), tmp]);
end
有了这个,您可以收集行,例如mat2cell
:
rows_per_year = ndays(1960:2000);
chunks = mat2cell(yourInputMatrix, rows_per_year, size(yourInputMatrix,2));
means = cellfun(@(x) mean(x,1), chunks);
(后半部分未经测试..)