MATLAB: Maximum value of a vector during specified intervals of time

datenumintervalmaximumseasontimevector

Hello folks,
I have two vectors, 32142×1, one is time in datenum format (variable='dn') and one is river discharge (variable='Q'). The discharge values occur once per day for 88 years from 1929-2016, and my goal is to find the maximum discharge value for each spring season during the months March-April-May. I want to end up with a vector 88×1 containing the maximum value of Q for each spring season only (i.e. if there was a larger discharge in the winter it would not be included). I feel this should be fairly straightforward but I can't come up with a good answer. Can someone assist me in this? Thank you!

Best Answer

DateV = datevec(dn);
Index = (3 <= DateV(:, 2) & DateV(:, 2) <= 5);
P = max(reshape(Q(Index), [], 88));