The first 3 lines re-create the input matrix named m. See inline comments to understand the rest.
It produces a table T summarizing the results.
d = datetime(1883,9,1) : days(1) : datetime(1950,12,31);
[yr,mo,dy] = datevec(d);
m = [yr(:),mo(:),dy(:),rand(size(yr(:)))*50+40];
winterMonths = [11, 12, 1];
isWinter = ismember(m(:,2), winterMonths);
L = bwlabel(isWinter);
maxDischarge = grpstats(m(:,4),L,'max');
maxDischargeYear = grpstats(m(:,1),L,'min');
maxDischargeYear(1) = [];
maxDischarge(1) = [];
T = table(maxDischargeYear(:),maxDischarge(:),'VariableNames',{'Year','MaxDischarge'});
Best Answer