필터 지우기
필터 지우기

Accumulate rain events with determined dry period

조회 수: 4 (최근 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 CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by