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

MathGroup Archive 2005

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

Search the Archive

Re: Extracting information from lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63346] Re: Extracting information from lists
  • From: dh <dh at metrohm.ch>
  • Date: Sat, 24 Dec 2005 16:02:55 -0500 (EST)
  • References: <dojefh$fmb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Tony,
one way to do it would be to:
1: mark runs of 1 (using Split)
2: replace all 1's of a run, except the first one, by 0
3: Determine the positions of the remaining 1's
e.g.

list={7,9,1,6,8,1,1,6,5,1,1,1,8,7,6,1,1,1,1,7};
t=Split[list]
t= t /. x:{1 ..} :> {1, Rest[x] /. 1 -> 0} // Flatten;
Position[t,1] //Flatten

Daniel


Tony King wrote:
> Does anyone know of a function that will allow me to extract the positions 
> of the first elements of runs of similar elements within a list. For 
> example, suppose that
> 
> list={7,9,1,6,8,1,1,6,5,1,1,1,8,7,6,1,1,1,1,7}
> 
> I need a function that will return
> 
> {3,6,10,16}
> 
> corresponding to the runs {1},{1,1},{1,1,1},{1,1,1,1} within list
> 
> Many thanks
> 
> Tony 
> 


  • Prev by Date: Re: Extracting information from lists
  • Next by Date: Re: Re: does this shut down anyone else's kernel?
  • Previous by thread: Re: Extracting information from lists
  • Next by thread: Re: Extracting information from lists