Accumulate rain events with determined dry period

1 回表示 (過去 30 日間)
Danilo M
Danilo M 2018 年 11 月 20 日
コメント済み: Danilo M 2018 年 11 月 21 日
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 件のコメント
Andrei Bobrov
Andrei Bobrov 2018 年 11 月 20 日
Please attach small example your data as mat-file.
Danilo M
Danilo M 2018 年 11 月 21 日
Here is an small example of rain data. The rain data is on 7th row.

サインインしてコメントする。

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2018 年 11 月 21 日
編集済み: Andrei Bobrov 2018 年 11 月 21 日
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);
  1 件のコメント
Danilo M
Danilo M 2018 年 11 月 21 日
Thanks Andrei! I could run the code without timetable and did exactly what I need.
I just have two doubts about the code. There's a way to put the hour on Time_interval table? Because I need to calculate rain intensity (mm/hour), so I need to know the exactly interval.
And if I want to change the dry period interval, like 36 or 48 hours without rain, what line I can make it?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTime Series Events についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by