# to determine rainfall data

7 views (last 30 days)
dira azman on 12 Dec 2019
Commented: Walter Roberson on 23 Dec 2019
hi, i have rainfall data in txt file. the data has 100 years of data. i want to determine the wettest and driest year, maximum, minimum and average for years and month.
to solve this i need to using loop function. with this i attach the data.
thanks.

Akira Agata on 12 Dec 2019
I would recommend using timetable and retime functions, rather than using for-loop.
The following is an example:
% Create timetable variable
Time = datetime(Data(:,1),Data(:,2),1);
Rainfall = Data(:,3);
TT = timetable(Time,Rainfall);
% Create yearly data
TTsum = retime(TT,'yearly','sum');
TTavg = retime(TT,'yearly','mean');
TTmax = retime(TT,'yearly','max');
TTmin = retime(TT,'yearly','min');
figure
subplot(2,1,1)
plot(TT.Time,TT.Rainfall,'.')
hold on
stairs(TTmax.Time,TTmax.Rainfall)
stairs(TTavg.Time,TTavg.Rainfall)
stairs(TTmin.Time,TTmin.Rainfall)
grid on
legend({'Original data','Max. for each year','Avg. for each year','Min. for each year'},...
'NumColumns', 2,...
'FontSize', 10)
subplot(2,1,2)
stairs(TTsum.Time,TTsum.Rainfall)
legend({'Sum. for each year'},...
'FontSize', 10)
grid on

Show 1 older comment
Akira Agata on 14 Dec 2019
Could you tell us why you need to use for-loop?
dira azman on 23 Dec 2019
the question said need to use fo-loop
Walter Roberson on 23 Dec 2019
if isempty(YourArray)
minval = [];
else
minval = inf;
for K = 1 : numel(YourArray);
if YourArray(K) < minval
minval = YourArray(K);
end
end
end