Selecting a rain event from data series
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi everyone. I hope you can help me. I have a time series of data: rain data (h in mm) recorded every 10 min in a day (column vector of 144 data). From the data I must select an event preceded and followed by 6 hours (36 data) without rain (h=0). How do I select the data range?
댓글 수: 2
Dyuman Joshi
2023년 8월 29일
편집: Dyuman Joshi
2023년 8월 29일
A scalar data value recorded every 10 min for a day would give 6*24 == 144 data points per day. (6 data point an hour * 24 hours in a day)
How many data points do you collect each hour? If 1, then how did you get 1440 elements? or did you collect data for 10 days?
"From the data I must select an event preceded and followed by 6 hours (36 data) without rain (h=0). How do I select the data range?"
Using conditional operations and logical indexing - Find Array Elements That Meet a Condition
채택된 답변
Alexander
2023년 8월 31일
편집: Walter Roberson
2023년 9월 9일
I think this should work now:
clear;
load rain2.txt; rain = rain2; % Only to reuse the code above
NoOfDry = 1;
rHmm = rain(:,2);rHmm = rHmm(:)'; % To force a row vector
tH = rain(:,1)/6; % Only to have a timeline in hours, doesn't needed here
figure(1);plot(rHmm);grid;
dryTime = zeros(1,36); % 6h dry, 36*10 minutes
yDry = strfind(rHmm, dryTime); % Now we are looking for the indices dry >= 6h
if(isempty(yDry))
fprintf('In your data set are NO period(s) with ge. 6h no rain\n');
NoOfDry = 0;
return;
end
yDryDiff = diff(yDry); % 1 means > 6h dry
iNoOffDry = find(yDryDiff > 1); % Here are the positions of dry >= 6h
NoOfDry = NoOfDry+length(iNoOffDry); % This is the number of occurences dry >= 6h
fprintf('In your data set are %i period(s) with ge. 6h no rain\n',NoOfDry);
commandwindow
댓글 수: 3
Alexander
2023년 8월 31일
I think it's a good idea to accept this answer if it fulfills your needs. ;-)
추가 답변 (2개)
Alexander
2023년 8월 30일
편집: Dyuman Joshi
2023년 8월 30일
I have to contradict, strfind is perfect if you want to avoid loops. Have a look at my rapid programmed script:
load rain.txt
tH = rain(:,1)/6; tH = tH(:)';% I prefere hours
rHmm = rain(:,2);rHmm = rHmm(:)'; % only for convenience
tHobs = tH(36:108); % I modified the observation time: 06:00 - 18:00
rHmmObs = rHmm(36:108);
figure(1);plot(tH,rHmm);grid;
dryTime = zeros(1,36); % 6h dry
figure(2);plot(tHobs,rHmmObs);grid;
yDry = strfind(rHmmObs, dryTime)
% Result: yDry = [], which means that no 6h w/o rain between 6-18:00
% Let's reduce the dry time to one hour:
dryTime = zeros(1,6);
yDry = strfind(rHmmObs, dryTime);
disp(yDry)
% There are a lot of consecutive numbers in, which means that there are dry
% periods which are longer than one hour. Let's test these:
yDryDiff = diff(yDry);
disp(yDryDiff)
% This means, you have one period of (6+11)*10 minutes w/o rain
% you have 2 periods with exact one hour w/o rain
% you have one period of (6+4)*10 minutes w/o rain
% To check item 1:
dryTime = zeros(1,17);
yDry = strfind(rHmmObs, dryTime);
disp(yDry)
댓글 수: 7
Alexander
2023년 8월 30일
I think I don't understand your problem. Are you looking for exact 6h dry (=0)? Or >= 6h dry? Just some code:
clear;
load rain2.txt; rain = rain2; % Only to reuse the code above
rHmm = rain(:,2);rHmm = rHmm(:)'; % To force a row vector
tH = rain(:,1)/6; % Only to have a timeline in hours, doesn't needed here
figure(1);plot(rHmm);grid;
dryTime = zeros(1,36); % 6h dry, 36*10 minutes
yDry = strfind(rHmm, dryTime); % Now we are looking for the indices dry >= 6h
yDryDiff = diff(yDry); % 1 means > 6h dry
iNoOffDry = find(yDryDiff > 1); % Here are the positions of dry >= 6h
NoOffDry = length(iNoOffDry); % This is the number of occurences dry >= 6h
fprintf('In your data set are %i period(s) with ge. 6h no rain\n',NoOffDry)
commandwindow
If you want to get the exact time or index you have just work off the indices backward.
Just a very small piece of advice: If you really want to use the large advantages of Matlab, you should get a little bit more familiar with it. ;-)
Alexander
2023년 8월 30일
There is an exception I've forgotten: the first matching pattern. But I'm currently not at my PC. Hence, I will update my code tomorrow. Sorry.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!