Selecting a rain event from data series
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Me
am 29 Aug. 2023
Bearbeitet: Walter Roberson
am 9 Sep. 2023
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 Kommentare
Dyuman Joshi
am 29 Aug. 2023
Bearbeitet: Dyuman Joshi
am 29 Aug. 2023
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
Akzeptierte Antwort
Alexander
am 31 Aug. 2023
Bearbeitet: Walter Roberson
am 9 Sep. 2023
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 Kommentare
Alexander
am 31 Aug. 2023
I think it's a good idea to accept this answer if it fulfills your needs. ;-)
Weitere Antworten (2)
Alexander
am 30 Aug. 2023
Bearbeitet: Dyuman Joshi
am 30 Aug. 2023
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 Kommentare
Alexander
am 30 Aug. 2023
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
am 30 Aug. 2023
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.
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!