Re: Segregating the elements of a list based on given
- To: mathgroup at smc.vnet.net
- Subject: [mg77402] Re: [mg77205] Segregating the elements of a list based on given
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 7 Jun 2007 04:15:00 -0400 (EDT)
- Reply-to: hanlonr at cox.net
binLyst[lyst_, bin_] := Module[{t}, t = Select[lyst, bin[[1]] <= # <= bin[[2]] &]; {bin, t, Length[t]}]; A = {6.32553, 7.09956, 8.56784, 16.1871, 15.3989, 17.2285, 7.40711, 14.8876, 19.9068, 10.0834}; B = {{0, 7}, {8, 10}, {11, 12}, {13, 15}, {16, 18}}; binLyst[A, #] & /@ B {{{0, 7}, {6.32553}, 1}, {{8, 10}, {8.56784}, 1}, {{11, 12}, {}, 0}, {{13, 15}, {14.8876}, 1}, {{16, 18}, {16.1871, 17.2285}, 2}} Bob Hanlon ---- "R.G" <gobiithasan at yahoo.com.my> wrote: > Hi Mathgroup members, > > Say, I have a list with the following elements: > > A={6.32553, 7.09956, 8.56784, 16.1871, 15.3989, 17.2285, 7.40711, \ > 14.8876, 19.9068, 10.0834} > > and I have the following list with each {xvalue, yvalue}={lower bound, > upper bound}: > B={{0, 7}, {8, 10}, {11, 12}, {13, 15}, {16, 18}} > > How can I segregate values in A according to lower bound and upper > bound from B and find the number number of occurrence ?For example: > {0,7}={6.32553}, thus the number of occurrence is 1. > {8, 10}={7.09956,7.40711,8.56784}, the number of occurrence is 3. > {11,12}=None, the number of occurrence is 0. > > The code should be able work for any number Length[A] and Length[B]. > Any suggestion please? > Thank you, > R.G > >