Accumulate rain events with determined dry period
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a rain time series with 15 minutes between data:
yyyy mm dd hh mm ss rain
2010 1 1 0 0 0 0.2
2010 1 1 0 15 0 0.4
2010 1 1 0 30 0 0
[...]
And I need to accumulate every rain value restarting the sum every time the station had at least 24 hours without rain, getting a matrix with start and end dates of each rain event and the accumulated rain during the period:
start_rain end_rain accumulated_rain
2010-1-1-0:0:0 2010-1-4-0:0:0 12
2010-1-7-0:0:0 2010-1-13-0:0:0 23
The date format above is only for exampe, could be in datenum
Any suggestions about how can I do this on MatLab?
Tks
2 commentaires
Réponses (1)
Andrei Bobrov
le 21 Nov 2018
Modifié(e) : Andrei Bobrov
le 21 Nov 2018
load('ex_rain.mat')
TT = timetable('RowTimes',datetime(example(:,1:6)),example(:,7),'v',{'rain'});
TT1 = retime(TT,'daily','sum');
p = TT1.rain~=0;
p1 = [0;p;0];
Time_interv = TT1.Time([strfind(p1(:)',[0 1]);strfind(p1(:)',[1 0])-1]');
ii = cumsum(diff(p1)==1);
ii = ii(1:end-1).*p + 1;
rain_int = accumarray(ii,TT1.rain);
rain_int = rain_int(2:end);
Rain_out = table(Time_interv,rain_int);
same variant but without timetable
[Date0,~,i0] = unique(example(:,1:3),'rows');
rain_daily = table(datetime(Date0),accumarray(i0,example(:,7)),'v',{'Date','rain'});
p = rain_daily.rain~=0;
p1 = [0;p;0];
Time_interv = rain_daily.Date([strfind(p1(:)',[0 1]);strfind(p1(:)',[1 0])-1]');
ii = cumsum(diff(p1)==1);
ii = ii(1:end-1).*p + 1;
rain_interv = accumarray(ii,rain_daily.rain);
rain_interv = rain_interv(2:end);
Rain_out = table(Time_interv,rain_interv);
Voir également
Catégories
En savoir plus sur Time Series Events dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!