how to find overlapping intervals?
20 次查看(过去 30 天)
显示 更早的评论
Hi, is there a function or an efficient way to find the overlap between two intervals represented in vectors. for example for a=[0 90 180 270]; and b=[26,180,270]; it should find the following overlaps and return the indices
26,90 (2,1) 90,180 (2,2) 180,270 (3,3) or (4,2) and the edges as well (as though the intervals are cyclic) 270,0 (1,4) 0,26 (1,1)
thanks
1 个评论
回答(4 个)
Cedric
2013-5-14
编辑:Cedric
2013-5-14
If boundaries are integer, a solution can built based on CUMSUM for building interval IDs and DIFF or UNIQUE for finding boundaries and IDs. I can develop this further if you are interested.
However, if all you have to do is to generate the list of intervals, without really caring for interval IDs, why couldn't you just go for something simpler, like:
>> bnd = unique([a, b]) ;
>> if bnd(end) < 360, bnd = [bnd, bnd(1)] ; end
>> int = [bnd(1:end-1); bnd(2:end)]
int =
0 26 90 180 270
26 90 180 270 0
0 个评论
Thomas
2013-5-14
Your question is a little ambiguous but her is something you can use
doc intersect
To see where the arrays overlap
[C,ia,ib]=intersect(a,b)
Ans
C =
180.00 270.00
ia =
3.00 4.00
ib =
2.00 3.00
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!