Re: Re: modified list interval calculation

• To: mathgroup at smc.vnet.net
• Subject: [mg21102] Re: [mg21058] Re: modified list interval calculation
• From: Hartmut Wolf <hwolf at debis.com>
• Date: Fri, 17 Dec 1999 01:21:03 -0500 (EST)
• Organization: debis Systemhaus
• References: <199912130451.XAA16217@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Deborah Leddon schrieb:
>
> Hi,
> I am having trouble with the problem below:
>
> I am trying to remove from list, t, those numbers in list, nt, that
> match and then I want to calculate the differences (intervals )
> between succesive numbers in list, t, that do not contain the
> removed number. For example:
> the two lists are;
> t = {1,4,4.5,6,7,8,8.9,9,10,12,140,16,16.8,17,18,
>         19,19.1,19.3,19.5,20}
> nt = {8,8.9,10,17}
>
> the resulting intervals would look like:
> 4 -1, 4.5 - 4, 6 - 4.5, 7 - 6, 140 -12, 16 - 140, 16.8 - 16, 19 - 18,
> 19.1 -19, 19.3 - 19.1, 19.5 - 19.3, 20 - 19.5
> and of course the final list would be:
> intervals = {3, .5, 1.5, 1, 128, -124, .8, 1, .1, .2, .2, .5};
>
> Note that 9 was omitted from the calculation of intervals because it
> would have been involved in a calculation with a removed number
> from the list, t.
>

Dear Debbie,

The following will do what you want:

In[4]:=
(#2 - #1) & @@@
DeleteCases[Partition[t, 2, 1], Alternatives @@ ({_, #} | {#, _} &) /@
nt]
Out[4]=
{3, 0.5, 1.5, 1, 128, -124, 0.8, 1, 0.1, 0.2, 0.2, 0.5}

Or alternatively:

In[5]:=
(#2 - #1) & @@@
Cases[DeleteCases[Partition[t, 2, 1], Alternatives @@ nt, {2}], {_,
_}]
Out[5]=
{3, 0.5, 1.5, 1, 128, -124, 0.8, 1, 0.1, 0.2, 0.2, 0.5}

Kind regards, Hartmut

```

• Prev by Date: Re: (Newbie) Applying colors to surface plots
• Next by Date: Re: centering a figure
• Previous by thread: Re: modified list interval calculation
• Next by thread: Re: Re: modified list interval calculation