I need to calculate the cumulative rainfall of 1, 2, 3, 4, 5, 6 and 7 days and extract the annual maximum of each year (after accumulation). I have historical series of precipitation with a great amount of years organized as follows: day, month, year, precipitation [mm], each in a column. I tried using the code below but it did not work.
%% Import Precipitation Data
RainMatrix = importdata ('data.txt');% Identifies the first and last year of the series
First_Year = RainMatrix(1,3);Last_Year = RainMatrix(end,3);% Measuring the Data Series Size;
T = length(unique(RainMatrix(:,3)));P = 2; % Time Step, P = 1, 2, 3, 4, 5, 6 and 7 days
k = 1; % Counter
for ii = 1 : (T-1) Year = find(RainMatrix(:,3) == First_Year); % Identifies the year
RainMatrix = RainMatrix(Year(:,1),:); % Cut the year
n = length(RainMatrix); % Dimension of Cut Out Data
for i = P : P : n Rainfall(k,1) = sum(RainMatrix(i-P+1:i,4)); % Cumulative rainfall of "P" days
k = k+1; [x, y] = ismember(max(Rainfall(:,1)),Rainfall(:,1)); % Find the Maximum Value of the Series
MaxAnual(ii,1) = Rainfall(y); end First_Year = First_Year + 1; Rainfall = [];end
Best Answer