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

MathGroup Archive 2007

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

Search the Archive

Re: problems with delayed write: tag list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79908] Re: problems with delayed write: tag list
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Wed, 8 Aug 2007 04:57:48 -0400 (EDT)

On 8/7/07 at 1:38 AM, peter_van_summeren at yahoo.co.uk (P_ter) wrote:

>I have a list of elements of two numbers:

>myList ={{1,2},{2,7},..}.

>The first number is in this case always the
>position. I want to know when the difference is a certain
>value,myDiff, eg. 5

>i=1;myDiff==5;
>now= Reap[While[i<Length[myList],i++;
>If[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w]

>My question is: how do I make "nowFunction[myDiff_]:="? I run into
>tag list errors in the definition when I try that. P_ter

It seems to me your code is more complex than necessary. Using
either Cases seems to me to be more efficient. First, generate
some data:

In[10]:= data =
  MapIndexed[Join[#2, {#1}] &, RandomInteger[{1, 20}, 20]]

Out[10]= {{1, 9}, {2, 18}, {3, 8}, {4, 4}, {5, 15}, {6, 19},
    {7, 8}, {8, 4}, {9, 18}, {10, 3}, {11, 19}, {12, 8},
    {13, 20}, {14, 17}, {15, 12}, {16, 11}, {17, 1},
    {18, 14}, {19, 13}, {20, 12}}

In[11]:= diff = 5;

In[12]:= Cases[data, _?(Subtract @@ # == -diff &)][[All, 1]]

Out[12]= {3}

Then nowFunction would be:

nowFunction[diff_, data_] :=
  Cases[data, _?(Subtract @@ # == -diff &)][[All, 1]]
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Projectile motion
  • Next by Date: Re: How to extract generated plot data (or mesh data) from a Graphics3D
  • Previous by thread: Re: problems with delayed write: tag list
  • Next by thread: Re: problems with delayed write: tag list