MathGroup Archive 1999

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

Search the Archive

Re: list manipulation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20610] Re: list manipulation
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 4 Nov 1999 02:13:28 -0500
  • References: <7vm3ud$q8r@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Jim,
Mathematica has convenient tools for doing what you want. Here are two
possibilities

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};

DeleteCases[events, n_ /;
    IntervalMemberQ[Interval @@ gaps, n]]

{6.7, 8.9, 10, 11.002}

DeleteCases[events, n_ /; Or @@ ((# <= n <= #2) & @@@ gaps)]

{6.7, 8.9, 10, 11.002}

I have not timed them on large lists - there is clearly some reduntant
testing for larger members of events.

I did find two errors in your coding (the error messages, coloring of
unbalanced brackets, and the menu function Edit>Check Balance are helpfull).
These are corrected in the following, but it does not seem to be doing what
you want and I have not looked into it further.

eout = {0};
max = Length[events];

Do[e = IntegerPart[events[[i]]];
  ei = events[[i]];
  tmp1 = Select[
      gaps, #[[1]] >= IntegerPart[e] && #[[2]] <= IntegerPart[e] &];
  For[j = 1, j <= Length[tmp1], j++,
    If[ei <= tmp1[[j, 2]] && ei = tmp1[[j, 1]], AppendTo[eout, ei]]], {i,
    max}];
Delete[eout, 1];

eout

{0}


Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565



jim leddon <jleddon at home.com> wrote in message
news:7vm3ud$q8r at smc.vnet.net...
>
> 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.
>
> 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};
> eout = {0};
> max = Length[events];
> Do[e = IntegerPart[events[[i]]; ei = events[[i]]; tmp1 =
> Select[gaps,
>
> #[[1]] >= IntegerPart[e] && #[[2]] <= IntegerPart[e] &];
>                             For[ j=1, j<= Length[tmp1], j++,
>                                         If[ ei <= tmp1[[j,2]] &&  ei .=
tmp1[[j,1]],
>                                         AppendTo[eout,ei]]
>                                         ],
>         {i,max}
>     ]
> Delete[eout,1];
> eout
>
>




  • Prev by Date: Re: Mathematica 4.0 NIntegrate
  • Next by Date: Mathematica link for LabVIEW
  • Previous by thread: Re: list manipulation
  • Next by thread: Re: BadAlgebra