Re: select a range of elements from a nested list

*To*: mathgroup at smc.vnet.net*Subject*: [mg5456] Re: select a range of elements from a nested list*From*: Clemens Frey <Clemens.Frey at uni-bayreuth.de>*Date*: Sat, 7 Dec 1996 00:26:34 -0500*Organization*: uni-bayreuth.de*Sender*: owner-wri-mathgroup at wolfram.com

Oliver Schurr wrote: > > Hi MathGroup > > Say you have a nested list like that {{x1,y1},{x2,y2},{x3,y3},...{xn,yn}} > basically containing X and Y values for a XY plot in each element. The X > values span a range from say 0 to 0.4 and you ONLY want to select the > elements (x,y values) from the list for which the x value spans say 0 to > 0.3. BUT you don't want to COUNT the elements (visually on the screen) and > figure out the position at which the x value is just greater than 0.3 and > then subtract 1 from this position. > > I still want do define the list by using > > Table[list[[x,1]],list[[x,2]],{x, 1, ZZZ}] > > here ZZZ means the number for which the x value <= 0.3, this number needs > to be found by MATHEMATICA! Hi, what about using the CASES-function to get a list of all pairs matching your condition ? Just look at this example: L = {{0.1,1},{0.2,2},{0.3,3},{0.4,4}}; For the upper list L use Cases to get a list M of all pairs having a first value <= 0.3 : M = Cases[ L, {x_Real,_} /; x<=0.3 ] Then you should have Length[M]==ZZZ of your example. _/; is a conditional pattern. I used x_Real instead of x_ alone to beware of errors if the list L contains only two pairs of numbers. Hope I could help you Clemens (-: Clemens.Frey at uni-bayreuth.de :-)