MATLAB Answers

how to find overlapping intervals?

조회 수: 58(최근 30일)
Itzik Ben Shabat
Itzik Ben Shabat 14 May 2013
댓글: Jan 26 Oct 2014
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

Jan
Jan 14 May 2013
I'm not sure, what "26,90 (2,1) 90,180 (2,2)..." should mean. Of course this notation is clear to you, but an exact definition for the forum would be a good idea also.

댓글을 달려면 로그인하십시오.

답변(4개)

Cedric Wannaz
Cedric Wannaz 14 May 2013
편집: Cedric Wannaz 14 May 2013
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
Thomas 14 May 2013
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

  댓글 수: 1

Itzik Ben Shabat
Itzik Ben Shabat 14 May 2013
i found this function too. but it doesnt doo what i mean. it finds equal parameters and not intervals. ill try to be more clear. imagine a straight line. this line begins at the first value of vector a. (in my example 0). the next point on tha line is defined by the second value in a (in my example 90) and so on... now imagine a second straight line right under the first one. this line is defined by the values in b. now if we draw vertical lines in each point of the lines we get areas whih overlap. the overlap is defined by a right and left vertical lines, each belongning to a different vector. was that more clear?

댓글을 달려면 로그인하십시오.


Jan
Jan 14 May 2013
What about histc()?

  댓글 수: 1

Itzik Ben Shabat
Itzik Ben Shabat 14 May 2013
interesting. didnt know this one. ill look at it closely. but its near the solution im looking for. not quite there yet...

댓글을 달려면 로그인하십시오.


Amani
Amani 26 Oct 2014
have you found a solution for this problem? histc does not solve it

  댓글 수: 1

Jan
Jan 26 Oct 2014
Please open a new thread and define your problem there exactly.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by