How to calculate the accumulated rainfall value of 1, 2, 3, 4, 5, 6 and 7 days.
Show older comments
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
4 Comments
darova
on 19 Apr 2019
You forgot to attach data
Walter Roberson
on 19 Apr 2019
When you do cumulative for a particular number of days, are you wanting to do distinct windows or sliding windows? d1, d2, d3, d4 -> (d1+d2), (d3+d4) or instead (d1+d2), (d2+d3), (d3+d4) ?
GA
on 19 Apr 2019
GA
on 19 Apr 2019
Accepted Answer
More Answers (0)
Categories
Find more on Time Series Events in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!