Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

RE: checking for overlap

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20095] RE: [mg20065] checking for overlap
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Thu, 30 Sep 1999 02:43:09 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Dennis (dennisw555 at aol.com) wrote:
-------------------------
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?
-------------------------

Dennis,
I give an example below that does the trick, and I suspect it's about as
fast and elegant as it gets.
 

In[1]:=
int=Interval[{1,3},{12,14},{15,16},{21,24},{35,40}];
tvals={2,4,5,15.4,33,34,36,,35,37};

In[3]:=
Select[tvals,IntervalMemberQ[ints,#]&]

Out[3]=
{2,15.4,36,35,37}

----------------------------
Note:
if you already have
  int={{1,3},{12,14},{15,16},{21,24},{35,40}};

Then you can change it to Interval[__] using
In[4]:=
  Interval@@int
  
Out[4]=
  Interval[{1,3},{12,14},{15,16},{21,24},{35,40}];


-----------------------------
If you don't understand the #& notation point your browser to 
(Slot, SlotSequence) at my web page.  The URL is given below.

-----------------------------
Regards,
Ted Ersek

For Mathematica tips, tricks see 
http://www.dot.net.au/~elisha/ersek/Tricks.html


  • Prev by Date: Re: Re: List-Selection
  • Next by Date: Re: checking for overlap
  • Previous by thread: Re: checking for overlap
  • Next by thread: Re: checking for overlap