COMPGROUPS.NET | Post | Groups | Users | Stream | Browse | About | |

### Sorting into bins

• Email
• Follow

```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}];

```
 0
Reply h.g.d.goyder (65) 6/15/2011 11:19:59 AM

See related articles to this posting

```.... 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...@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}];

```
 0
Reply dana.del (86) 6/17/2011 4:07:10 AM
 comp.soft-sys.math.mathematica 28834 articles. 9 followers.

1 Replies
123 Views

Similar Articles

[PageSpeed] 42

• Email
• Follow

Similar Artilces:

/bin/sort fails for: 2gb file, same output filename
Any ideas on why / how to fix? On Solaris 9 (uname shows 5.9), running in 64-bit mode, the 2 sort executables behave in the same way: sort: can't mmap /u01/bigdir/myfile: Not enough space But - it succeeds when in & out filenames DO differ. There is plenty of disk free, 13 GB. The command: sort -o /u01/bigdir/myfile -k3,3 -k4,4nr -k5,5 -k6,6nr -k7,7 -k8,8nr \ -t'|' -T /tmp/ /u01/bigdir/myfile i.e. - output filename is SAME as input filename Input file size: 2.4 GB. This is cured by CHANGING output (or input) filename: sort -o /u01/bigdir/myfile.NEW -k3,3 -k4,4nr -k5,5...

Sorting out sort
I'm trying to extract a column from a flatfile database and print it alphabetically. I can get the data out, but I can't get it to sort. The database is pipe-separated in a plain text file and looks like this: Ref_no|Title|County|Another_field|And_another|And_another 1234|A Name|Devon|Data here|More data here|And more data 1234|A Name|Somerset|Data here|More data here|And more data 1234|A Name|Nottinghamshire|Data here|More data here|And more data 1234|A Name|Essex|Data here|More data here|And more data .... and so on My routine is as follows: #open the file open (INFILE, 'dat...

~bin and ~/bin ??
Hi All, Quick query on something i dont understand!!! there are many echo ~ /home/myprod/myprod echo ~/bin /home/myprod/myprod/bin Which I am okay with and totaly understand but why does echo ~bin give /usr/bin I dont understand how the shell interperets ~bin??? Boab <google@robertbrewer.co.uk> wrote: > Which I am okay with and totaly understand but why does > > echo ~bin > give > /usr/bin > > I dont understand how the shell interperets ~bin??? You forgot to say which shell you are using. Your shell expands ~bin to the home directory of the user 'bin&#...

sorted or .sort() ?
My poor understanding is that the difference between `sorted(somelist, key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one returns a new list and the other sorts in-place. Does that mean that .sort() is more efficient and should be favored when you can (i.e. when you don't mind changing the listish object)? Peter Bengtsson <peterbe@gmail.com> writes: > My poor understanding is that the difference between `sorted(somelist, > key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one > returns a new list and the other sorts in-place. Yes. > Does th...

differences between /bin, /usr/bin and /usr/local/bin
Hello, What are the differences between /bin, /usr/bin and /usr/local/bin? I dont understand how the binaries are sorted out in these three directories. If someone can clarify, i'd appreciate it. In article <87fbf9fb.0309161118.6f57ac0e@posting.google.com>, gorda wrote: > Hello, > > What are the differences between /bin, /usr/bin and /usr/local/bin? I > dont understand how the binaries are sorted out in these three > directories. If someone can clarify, i'd appreciate it. This differs between different Unix and Unix-like operating systems. /bin Statically ...

Sorting and re-sorting
I'm creating a shopping cart type system where users can add a bunch of products. It's important that users can change the display order of products. This way they can showcase certain items on top. All of this is stored in the database obviously. There is a problem though, and it's with the sort order storage in the database. For instance, if I have 5 products, I can set it like this: 01 A 10 B 20 C 30 D 40 E The number is the "sort" field, and the letter is the "product" field. I'd then set an index for the "sort" field and the listings would...

sort cmd
Having problems with sort (ver. 5.93 on SUSE 10.1). I have a 1.5 GB file which I sort with: sort -t ' ' -k 6 --output=sorted.txt data.txt This runs for a few minutes and gives me a file where things is sorted in sets, like aa aa bb bb bb cc dd dd ss xx bb bb cc cc cc dd ss ss Not what I expected, hoping to get the entire file sorted as one and not have a file with several sets which is sorted. Any ideas, what am I doing wrong? Thanks, Claus On Thu, 11 Jan 2007 06:01:51 -0800, nesalc wrote for every to trash: > Having problems with sort (ver. 5.93 on SUSE 10.1). > > I ...

Sub-sort after sort
Hello, I have been sorting a list of dicts using the following function: result_rs = sorted(unsort_rs, key=itemgetter(orderby)) and this works fine. Now I am looking to perform a subsort as well. For example, I have this: test = [{'name': 'John Smith', 'location': 'CA',},{'name': 'John Smith', 'location': 'AZ',},] I would want to sort by name first, then sub sort by location. Any ideas? Thanks! On Nov 2, 2:45 pm, kee...@gmail.com wrote: > Hello, I have been sorting a list of dicts using the following > function: > &...

/bin and /usr/bin?
Dear all, I found out /bin and /usr/bin contain the same command binaries such as "ls" and "rm". Is there any reason why the both directories contain the same(?) command files? or are the commands different? Can't we just use link instead? cheers, AK On 2008-07-12, Alexander Dong Back Kim <alexdbkim@gmail.com> expressed: > Dear all, > > I found out /bin and /usr/bin contain the same command binaries such > as "ls" and "rm". > Is there any reason why the both directories contain the same(?) > command files? or are the comman...

reinstall /usr/bin/ar, /usr/bin/make, /usr/bin/nm, /usr/bin/ld
Hi, I've removed the following files from my AIX 5.1 station: ar, make, ld and nm (in /usr/bin). I have AIX install media but couldn't guess what I have to install. Could anyone tell me where I can find them and how I should re-install them? Thank you for your help, dpimanu <svdcb@yahoo.com> wrote: d> Hi, d> I've removed the following files from my AIX 5.1 station: ar, make, ld d> and nm (in /usr/bin). I have AIX install media but couldn't guess what d> I have to install. d> Could anyone tell me where I can find them and how I should re-install d> th...

#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1...
""All external data is dangerous. Don't let it close to interfaces that can modify your system." http://www.rubycentral.com/book/taint.html what does #!/usr/bin/ruby -w do? is #!/usr/bin/ruby -T1 the same as -T with \$SAFE=1? Why not always use -T with a safety level of at least 1? "Walter should have run his CGI script at a safe level of 1,This would have raised an exception when the program tried to pass form data to eval" In what log file do exceptions show up? "He could have chosen to implement a proper expression parser, bypassing the risks inherent i...

Array sort function sorts on chars not numbers ... help ! how to sort numbers
My question is ... How do I sort an Array on numeric, not character values ? In the example below, after sorting the contents are 1,10,2,3 . How do I get the contents to be 1,2,3,10 ? Thanks, em <html> <head> <script> function TestSort() { var nums = new Array(0); nums[0] = 1; nums[1] = 2; nums[2] = 10; nums[3] = 3; nums.sort(); for ( i = 0 ; i < 4 ; i++ ) { alert(nums[i]); } return true; } </script> </head> <body bgcolor="lightblue"> <input type="button" onclick="TestSort();&quo...

insertion sort and string sorting
I have a structure with a numeric field and a pointer to char: typedef struct s { int numero; char *carattere; } strutt; I have created, then, an array of structure: strutt *arr; arr = (strutt *)malloc(32 * sizeof(strutt)); I can insert a new element as: arr[0].numero = 5; arr[0].carattere = "qwerty" When this dynamic array of structure will be full, it can be necessary to sort it. I need to sort it with insertion sort algorithm, this is how I have implemented: void insertion_sort(strutt *x, int length) { strutt key; int i,j=1,scambi=0; for(j=1;j<leng...

Sorting records using sort()
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the number of records. Both these numbers are known only dynamically. I have a function less_than that can compare two records of size m given the pointers to the two records. Is there an easy way to call STL sort() on this data and sort it. The data is big and I do NOT want to allocate a list of pointers of size n or anything linear in size. Assume that except the data, we do not have much space... I thoug...

Sorting Where Sort Field Is Null
My report has a text field named ItemNum. Most records have a value for ItemNum. I set Grouping And Sorting to sort ascending on the ItemNum field. The records where ItemNum is Null appear at the top of the list in the report. I want the records that have a value for ItemNum to be first in the report and sorted ascending and I want the records where ItemNum is Null to be at the end of the report. How do I do this? Thanks for all help! Marie Set the sorting and grouping field/expression to something like: =Nz([ItemNum], "zzzzzzzz") or =Nz([ItemNum],999999999) This depends on your...

Binning with specified bin width
Hi, I have a question about binning in Matlab. I want to make a histogram from a data set and I want to set the bin width but not the number of bins. How can I do that using hist? Thank you very much. Bests, Tung On Jul 12, 9:44=A0pm, "Tung Le" <dexture...@yahoo.com> wrote: > Hi, I have a question about binning in Matlab. > I want to make a histogram from a data set and I want to set the bin widt= h but not the number of bins. How can I do that using hist? > Thank you very much. > Bests, > Tung -------------------------------------------------------------------...

Selection sort and bubble sort
Selection sort and bubble sort have same performance always, right? Are the following correctly implemented the both functions. Comments are welcome. Selection sort an array of intergers range between index l and r in ascending order. For example, sort "312" into "123" void sort_sel(int a, int l, int r) { int i, j, n; for (i = l; i < r; i++) for (j = i + 1; j <= r; j++) if (a[i] > a[j]){ n = a[i]; a[i] = a[j]; a[j] = n; } } Bubble sort an array of intergers range between index l and r in ascending order. For example...

sort algorithm in sort.m
which sort algorithm does sort.m use? qsort? radix sort? Thanks Tommy <yiptommy@yahoo.com.hk> writes: > which sort algorithm does sort.m use? > qsort? radix sort? See this article: http://www.mathworks.com/company/newsletters/news_notes/dec04/adventure.html -- Steve Eddins Development Manager, Image Processing Group The MathWorks, Inc. "Tommy" <yiptommy@yahoo.com.hk> wrote in message news:eefb5b2.-1@webx.raydaftYaTP... > which sort algorithm does sort.m use? > qsort? radix sort? > > Thanks Look at the Programming Patterns article in the most ...

Sort order of a sorted array
With the PHP command 'sort' I can sort an array. However, it doesn't exactly sort the array I'd like to: <html> <body> <?php \$my_array[0] = array("AA", "11"); \$my_array[1] = array("AA", "22"); \$my_array[2] = array("aa", "22"); \$my_array[3] = array("AB", "11"); \$my_array[4] = array("ab", "11"); \$my_array[5] = array("ab", "22"); \$my_array[6] = array("�b", "11"...

Sorting with NaNs (sort Index)
Hi, Suppose I have an array a = [12 23 NaN 4 9]'. I want to generate teh sort index by doing [sort, index]= sort(a, 'descend') index = [4 5 1 3 2] The sort part is fine. But in the index, the NaN get listed as 1. I want to create a sort index that makes the NaN apprear as NaN, and the remaining observation to be sorted. i.e. i want index = [NaN 3 2 5 4] any help would be appreciated. thanks, sushma sushma sharma: <SNIP wants to see his/her <nan>s after sorting... one of the many solutions v=[12 23 NaN 4 NaN 9]; [is,is]=sort(v,'descend'); in=...

How to re-sort a sorted query?
This is a multi-part message in MIME format. ------=_NextPart_000_002D_01C4BB67.5DAF1F40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a query that need to be sorted in order of price of store's product = with unique store number. Here is a sample data of storeproduct table: ItemSku , StoreNumber , Price =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D 10001 , 7 , 30.00 10001 , 7 , 35.00 <-- duplicate store number=20 10001 , 5 , 45.00 10001 , 2 , 50.00 Then I do this...

memory sort and disk sort
I check the sysprofile table and find there are 700 times disk sort, I think it is lack of sort memory. I want to turn all the disk sort into the memory sort ,but how can I malloc more sort memory for informix? Now my shmvirtsize is 800000(800M) Another question is: my server run with 99% read cache hits but just 75% write cache hits, how can I mprove the write cache hits ? Thanks -- Posted via http://dbforums.com On Thu, 23 Oct 2003 03:15:11 -0400, dusong wrote: Version and platform information is important! For example 7.31UD4 (and IB 9.30)...

Sort
I have a problem with sort. I have to calculate in a table how many times an individual user appears; I also have to show 3 users who appear the most. Can somebody please help with an example of how to do this? Thanks I'm assuming this is a MySQL question. Here's a query that illustrates how to count repititions in table: SELECT COUNT( userid ) AS repetitions, userid FROM `table` GROUP BY userid ORDER BY repetitions DESC This would return a list of distinct userids and the number of times each userid appeared in the table, in descending order. "jacki" <jacki@jac...

sort
Is it possible to sort a table according to a heading (<th>) by cliking that header? If I have like this NAME UNIT RATE name1 unit1 rate1 name2 unti2 rate2 name3 unit3 rate3 Now if I click for example RATE it would sort them. Is this possible with XSL ? Within the onclick event start an XSLT transformation passing to it as parameter the name of the column, which is to be used for sorting. A complete example can be found in Mike Kay's book. See also: http://dpawson.co.uk/xsl/sect2/N6461.html#d6859e950 ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.ne...