From: Thomas Dowling on 16 Jul 2010 06:59 Hello lst = {{0, -4, 2.283}, {0.5, -4, 2.282}, {1, -4, 2.280}, {1.5, -4, 2.276}, {2, -4, 2.271}, {2.5, -4, 2.264}, {3, -4, 2.255}, {3.5, -4, 2.242}} Select[lst, Part[#, 3] > (2.25 - 0.01) && Part[#, 3] < (2.25 + 0.01) &] Out[26]= {{3, -4, 2.255}, {3.5, -4, 2.242}} Select[lst, Part[#, 1] == 0 &] Out[27]= {{0, -4, 2.283}} Tom Dowling On Thu, Jul 15, 2010 at 8:09 AM, Chris Poole <chris(a)chrispoole.com> wrote: > I have a list like this: > {{0, -4, 2.283}, {0.5, -4, 2.282}, {1, -4, 2.280}, {1.5, -4, > 2.276}, {2, -4, 2.271}, {2.5, -4, 2.264}, {3, -4, 2.255}, {3.5, -4, > 2.242}} > > I want to look at each list of 3 numbers, and keep only the lists where the > third item in each list fits some criteria. > > I can do something like this: > Select[{2, 15, 1, 16, 17}, Abs[3 - #] < 3 &] > > But it only works for flat lists. > > For example, I want only the lists where the third item is around 2.25 +- > 0.001. Something like that. > > I can work out how to get Select to operate on the 3rd item of each > sublist, but not how to then keep that entire list. > > If anyone has any ideas, they are much appreciated. > >
From: Robert McHugh on 17 Jul 2010 08:15 Will the following be satisfactory? * iFieldA = 3; iTolA = 0.01; iStepA = 2.25 t = {{0,-4,2.283},{0.5,-4,2.282},{1,-4,2.280},{1.5,-4,2.276},{2,-4,2.271},{2.5,-4,2.264},{3,-4,2.255},{3.5,-4,2.242}}; t // TableForm u=Select[t,((Abs@(#[[1]]-iStepA))<iTolA)&@{#[[iFieldA]]}&]; u // TableForm I have struggled with a similar problem for the last month. See posting "Using GatherBy, Select, and Sort to process data." Posted this month. Best Regards, Robert McHugh --------------------------------------------------------- I have a list like this: {{0, -4, 2.283}, {0.5, -4, 2.282}, {1, -4, 2.280}, {1.5, -4, 2.276}, {2, -4, 2.271}, {2.5, -4, 2.264}, {3, -4, 2.255}, {3.5, -4, 2.242}} I want to look at each list of 3 numbers, and keep only the lists where the third item in each list fits some criteria. I can do something like this: Select[{2, 15, 1, 16, 17}, Abs[3 - #] < 3 &] But it only works for flat lists. For example, I want only the lists where the third item is around 2.25 +- 0.001. Something like that. I can work out how to get Select to operate on the 3rd item of each sublist, but not how to then keep that entire list. If anyone has any ideas, they are much appreciated. *
First
|
Prev
|
Pages: 1 2 3 Prev: Accessing static members with J/Link Next: how to display the value of w after using do? |