MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: checking for overlap

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20111] Re: [mg20065] checking for overlap
  • From: BobHanlon at aol.com
  • Date: Thu, 30 Sep 1999 02:43:17 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Dennis,

Here is one way:

findInterval1[tvals_List, ints_List] := 
  Select[Flatten[Outer[List, tvals, ints, 1, 1], 
      1], #[[2, 1]] <= #[[1]] < #[[2, 2]] &]

Note that the proper test criteria depends on whether the intervals are 
closed or open (on right or left or both).

tvals  = Sort[Table[12*Random[], {10}]]

{0.66776, 1.53389, 1.85253, 2.07472, 2.58448, 5.6082, 7.28918, 7.53907, \
10.3284, 11.4026}

If the intervals do not overlap then a tval can be in only one interval

ints = {{1, 3}, {3, 4}, {4, 8}, {8, 10}};

findInterval1[tvals, ints]

{{1.53389, {1, 3}}, {1.85253, {1, 3}}, {2.07472, {1, 3}}, {2.58448, {1, 
      3}}, {5.6082, {4, 8}}, {7.28918, {4, 8}}, {7.53907, {4, 8}}}

Transpose[%][[1]]

{1.53389, 1.85253, 2.07472, 2.58448, 5.6082, 7.28918, 7.53907}

If the intervals do overlap, then a tval can be in more than one interval

ints = {{1, 3}, {2, 4}, {3, 8}, {7, 10}};

findInterval1[tvals, ints]

{{1.53389, {1, 3}}, {1.85253, {1, 3}}, {2.07472, {1, 3}}, {2.07472, {2, 
      4}}, {2.58448, {1, 3}}, {2.58448, {2, 4}}, {5.6082, {3, 
      8}}, {7.28918, {3, 8}}, {7.28918, {7, 10}}, {7.53907, {3, 
      8}}, {7.53907, {7, 10}}}

Union[Transpose[%][[1]]]

{1.53389, 1.85253, 2.07472, 2.58448, 5.6082, 7.28918, 7.53907}

Bob Hanlon

In a message dated 9/29/1999 8:45:44 AM, dennisw555 at aol.com writes:

>I am looking for an elegant way of checking for overlap.  
>
>Suppose I have a set of time intervals given by
>ints = {{t1,t2},{t3,t4},{t5,t6}. ...} and another set of times
>tvals = {u1,u2,u3, ...}.
> What is a fast, elegant way of checking which of the tvals is within any
>of
>the ints time intervals?
>


  • Prev by Date: greek alphabet
  • Next by Date: Preventing plotting on output
  • Previous by thread: Re: checking for overlap
  • Next by thread: Re: checking for overlap