How can I check overlap between event markers?
16 views (last 30 days)
Show older comments
Hello! I have a question concerning indexing and finding overlapping events within a time series. I have an array rain_data and an event_start/event_end array with the index of an event start and event end stored in the two index arrays.
I would like to exclude events that may have an overlap effect, which can take up to three days. For this, I therefore have to eliminate all events where 1. the end index at i + 3 days is larger then the start index at i+1; 2. the start index at i - 3 days is smaller than the end index at i-1.
The rain_data array consists of a first column in datenum with the respective times, and the second column is the rain data, although the rain data is irrelevant for this procedure.
Essentially, if I call up rain_data(event_start(i),1)), I get the starting time of an event, and the ending time can be drawn using rain_data(event_end(i),1)).
I have tried using different loops but I never end up getting the right eliminations in the indexes. Is there a more efficient way to do this?
An example of what I have tried:
rain_start=rain_data(start_event,1);
rain_end=rain_data(end_event,1);
for i=1:length(rain_start)
for k=1:length(rain_end)-1
if k>1
if rain_start(i)-3 > rain_end(k-1)
event_marker(i,:)=event_marker(i,:);
end
end
end
end
Where event_marker is simply the start and end index arrays put together. This doesn't work though.
5 Comments
Jan
on 8 May 2017
@Nina: Do you see that event_marker(i,:)=event_marker(i,:) is meaningless? It does nothing but assigning the contents of event_marker(i,:) to event_marker(i,:). No command in your posted code does something like "eliminating".
I still cannot follow your descriptions.
I simply put both the event_start and event_end index arrays
together into event_marker to make the elimination simpler.
What is "event_start"? I only find "rain_start" and "start_event".
I'm deeply confused. Please rephrase the question again as lean as possible. It does not matter, if the problem concerns rain. What exactly are the inputs? Can you post them such, that the readers can use them by copy&paste? What is the wanted output and which values should be "eliminated" - and what does "elimination" mean here (what is set to 0?)?
Answers (1)
Guillaume
on 8 May 2017
According to your description, you would eliminate both overlapping events. I'm not sure why you could not just eliminate one and leaves the other one since it would no longer be overlapping.
Obviously, if event i overlaps with event i+1, then i+1 overlaps with i, so there's no point searching for both your 1) and your 2). Loops are not needed in any case:
rain_start=rain_data(start_event,1);
rain_end=rain_data(end_event,1);
isoverlap = rain_end(1:end-1) + 3 > rain_start(2:end); %find where events overlap
todelete = any([[isoverlap; false], [false; isoverlap]], 2); %true in 1st column: delete because it overlaps with next. true in 2nd column: delete because it overlaps with previous. Combine both columns with OR (any)
start_event(todelete) = []; %actually delete
end_event(todelete) = []; %start and end
0 Comments
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!