Re: Sorting into bins
- To: mathgroup at smc.vnet.net
- Subject: [mg119668] Re: Sorting into bins
- From: Dana DeLouis <dana.del at gmail.com>
- Date: Fri, 17 Jun 2011 00:07:04 -0400 (EDT)
... I wish to sort a list of {{x,y}...} values into uneven bins using the x values Hi. Not sure, but here's one general method. A general function that divides you x values based on size. (I'll use Log10, but you can use your function here.). f[x_]:=Log10[x]//Floor Some Random data of length 2,3,& 4 I suggest Sorting the list here as it makes the code later a little easier. t=RandomInteger[{1,2000},{10,2}]//Sort; t//MatrixForm (18 592 49 1441 67 672 670 713 1318 1827 1417 1487 1437 586 1594 40 1600 1908 1786 1564 ) GatherBy[t,f[First[#]]&] { {{18,592},{49,1441},{67,672}}, {{670,713}}, {{1318,1827},{1417,1487},{1437,586},{1594,40},{1600,1908},{1786,1564}} } As you see, the bins are based on digit lengths of 2, 3 or 4. You'll have to think of your own function here. = = = = = = = = = = HTH : >) Dana DeLouis $Version 8.0 for Mac OS X x86 (64-bit) (November 6, 2010) On Jun 15, 7:19 am, Hugh Goyder <h.g.d.goy... at cranfield.ac.uk> wrote: > I wish to sort a list of {{x,y}...} values into uneven bins using the > x values to locate the bin but have the bins contain the y values. > This seems like an application for BinLists but it only seems to work > on a list of x values. The motivation is to give a spectra in terms of > 1/3 octaves which is a standard presentation in acoustics. Below I > construct the bin center frequencies cf, the bin boundaries bb and > generate a time history th, spectra, yy and corresponding frequencies > xx. How do I then sort the list into my bins? > > Thanks > Hugh Goyder > > cf = Table[(1/100.) Round[100 (1000/1024) 2^n], {n, 1, 15, 1/3}]; > bb = Table[Sqrt[cc[[i]]*cc[[i + 1]]], {i, 1, Length[cc] - 1}]; > sr = 60000.; > th = Table[y, {y, 0, 1, 1/sr}]; n = Length[th]; > yy = Take[ > Fourier[th, FourierParameters -> {1, -1}], {1, Ceiling[n/2]}]; > xx = Table[f, {f, 0, sr/2, sr/n}]; > data = Transpose[{xx, yy}];