Here is my solution:
I notice that you've got few NaNs for about a year and a half. Your last year is also incomplete.
I isolated each year, and then reshaped the data in blocks of 1,2, ... 7. I dropped a few days at the end of the year if they were not exact multiples. I then summed the cols, and then took the max and stored it in an array.
RainMatrix = importdata('data.txt');
yr = RainMatrix(:,3);
yr1 = yr(1); yr_end = yr(end);
Raincum = NaN(yr_end-yr1+1,7);
k=0;
for i=yr1:yr_end
k=k+1;
idx = find(yr == i);
yri = yr(idx); r = RainMatrix(idx,4); nr = length(r);
length(yri);
Raincum(k,1) = max(r);
for j=2:7
rv = r(1:nr - mod(nr,j));
r2 = reshape(rv,j,length(rv)/j);
r2 = sum(r2);
Raincum(k,j) = max(r2);
end
end
yrs = [yr1:yr_end]';
plot(yrs,Raincum)
legend('1','2','3','4','5','6','7')
Best Answer