Re: checking for overlap
- To: mathgroup at smc.vnet.net
- Subject: [mg20087] Re: checking for overlap
- From: "Stephen P Luttrell" <luttrell at signal.dra.hmg.gb>
- Date: Thu, 30 Sep 1999 02:43:05 -0400
- Organization: Defence Evaluation and Research Agency
- References: <7ssfbm$bgd@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
> DennisW555 <dennisw555 at aol.com> wrote in message news:7ssfbm$bgd at smc.vnet.net... > 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 Preamble: I have $Version = "4.0 for Microsoft Windows (April 21, 1999)" Here is an example of how you can solve this one: 1. Generate a list of 10 random intervals in [0,1]. ints = Table[{Random[], Random[]}, {10}] 2. Generate a list of 3 random numbers in [0,1]. tvals = Table[Random[], {3}] 3. Form the Outer product of these two lists, feeding the arguments appropriately to the interval membership function IntervalMemberQ. mems = Outer[IntervalMemberQ[Interval[#1], #2] &, ints, tvals, 1] The result of this is a list of lists with all of the results you required. Here are the results of an example run: ints = {{0.79438, 0.947129}, {0.355177, 0.291621}, {0.599038, 0.879794}, {0.649917, 0.266863}, {0.262309, 0.714362}, {0.179651, 0.0462716}, {0.387754, 0.0416916}, {0.381449, 0.46665}, {0.534931, 0.2277}, {0.364545, 0.148582}} tvals = {0.708023, 0.229474, 0.951056} mems = {{False, False, False}, {False, False, False}, {True, False, False}, {False, False, False}, {True, False, False}, {False, False, False}, {False, True, False}, {False, False, False}, {False, True, False}, {False, True, False}} -- Stephen P Luttrell Room EX21, Defence Evaluation and Research Agency Malvern, Worcs, WR14 3PS, U.K. luttrell at signal.dera.gov.uk 01684-894046 (phone), 01684-894384 (fax) http://www.dera.gov.uk/cis5pip/Welcome.html