Re: List manipulations
- To: mathgroup at smc.vnet.net
- Subject: [mg20624] Re: List manipulations
- From: Ranko Bojanic <bojanic at math.ohio-state.edu>
- Date: Thu, 4 Nov 1999 02:13:36 -0500
- Organization: Ohio State University
- Sender: owner-wri-mathgroup at wolfram.com
On Tuesday, November 2, 1999, Debbie L. wrote:
> Hi Folks,
> The program below takes the each value of the list,"events",finds
> which of these values falls within the intervals {x,y} which comprise
> the list,"gaps",then removes these values from the events list and
> outputs this modified list which is called "eout". I'm getting an
error
> for incomplete expression, although I'm not sure if the algorithm
itself
> is doing the job. These reason why I wrote the loop to cue on the
> integer parts of both lists is because these lists will eventually be
> quite large, about 3000 elements each in which case I wanted to make
the
> process more efficient.
> Thanks if anyone can help.
> Debbie L.
> ....
Debbie:
If I have understood correctly, you have a list of intervals and a list
of numbers and you want to find the numbers which are not in any of the
intervals:
gaps = {{1, 5.5}, {2, 4.3}, {2.7, 3.1}, {3.002, 4.007}, {10.001,
10.007}, {10.101, 11.001}, {11.007, 12.0}};
events = {6.7, 8.9, 2.3, 2.789, 10, 11.002, 10.115, 3.02, 2.75};
If we denote by x a number and by y a list of intervals,the new list
can be obtained easily as follows:
In[1]:=
test[x_, y_] :=
Module[{len = Length[y], in = True},
For[j = 1, j ? len, j++,
If[y[[j, 1]] ? x && x ? y[[j, 2]], in = False; Break]];
Return[in]];
In[2]:=
Select[events, test[#, gaps] &]
Out[2]=
{6.7, 8.9, 10, 11.002}