Sorting into bins

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
6/15/2011 11:19:59 AM
comp.soft-sys.math.mathematica 28833 articles. 9 followers. Follow

1 Replies
146 Views

Similar Articles

[PageSpeed] 34
.... 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
dana.del (86)
6/17/2011 4:07:10 AM
Reply:
Similar Artilces:

MakeIndex sort
Hey all, I am running MiKTex on Windows XP, and am trying to sort entries numerically in my index. The entries are like this: 43-200, 55-300, 34-20, 90-220. They should be sorted by the number preceeding the hyphen and then by the number after the hyphen. Haven't been able to do this. Tried installing xindy for windows, didn't see to work. Thoughts? ...

sorting in a matrix
Suppose I have a matrix say A = [1,2,3 ; 4,5,6 ; 7,8,9 ; 10,11,12] I want to sort its columns in descending order. Is it possible? "Samoline1 Linke" <maganatewoman@yahoo.com> wrote in message <hk64lm$peb$1@fred.mathworks.com>... > Suppose I have a matrix say A = [1,2,3 ; 4,5,6 ; 7,8,9 ; 10,11,12] > > I want to sort its columns in descending order. Is it possible? sort(A) See function "sort" in the help. ...

Sorting based on existence of keys
Hi experts Say I have an array @ks containing some strings which may or may not exist as keys in a hash %h. How do I sort @ks such that the non-existent keys come last (in any order), while the existing keys are sorted using, say, length($h{$a}) <=> length($h{$a}) (that is not really the property of the values I'll sort by, but that's not important). my @ks = qw(two three one four); my %h = ( one => 1, three => 333 ); for (sort { exists $h{$b} cmp exists $h{$a} || length $h{$a} <=> length $h{$b}} @ks) { print "$_\n" } This produces the in...

sorting
I use this script to retrieve all my .txt files in the current directory... Now the retrieved filenames all consist of a certain number followed by .txt, like 1.txt, 77.txt, 44.txt and so on.. Now is my question how do I sort these filenames in a correct way ? Since the sort function treats items as strings not as integers. Basicly I need to retrieve the highest number of the .txt files... opendir (homedir,".") || die("unable to open directory"); while (defined($filename=readdir(homedir))){ if ($filename=<*.txt>){print qq{$filename<br>};} } close...

[OT..sort of]: IBM lifts global hiring forecast to 18,800
What's HP doing? --------------------------- Aug. 13, 2004. 01:00 AM IBM lifts global hiring forecast to 18,800 NEW YORK-International Business Machines Corp. will hire 8,800 more people this year than it had earlier expected, due in part to growth in its worldwide services business, the company said yesterday. IBM said it would take on 18,800 new employees globally in 2004, up from its previous forecast of 10,000 for this year in January. The company had later indicated to Reuters that its hiring could be as high as 15,000, one-third from universities and the rest experienced prof...

sort order for strings of digits
I learn lots of useful things from the list, some not always welcome. No sooner had I found a solution to a minor inconvenience in my code, than a recent thread here drew my attention to the fact that it will not work for python 3. So suggestions please: TODO 2012-10-22: sort order numbers first then alphanumeric >>> n ('1', '10', '101', '3', '40', '31', '13', '2', '2000') >>> s ('a', 'ab', 'acd', 'bcd', '1a', 'a1', '222 bb', '...

How to convert a .tif image to a .bin (binary) file??
Can anyone tell me how to convert a .tif image to a .bin (binary) file?? Thanks, Ross "Ross " wrote > Can anyone tell me how to convert a .tif image to a .bin (binary) file?? > > Thanks, > Ross First define the format of the .bin file. Oliver ASCII image format. Ross "Oliver Woodford" wrote in message <j6f4p5$47b$1@newscl01ah.mathworks.com>... > "Ross " wrote > > Can anyone tell me how to convert a .tif image to a .bin (binary) file?? > > > > Thanks, > > Ross > > First define the format of the .bin fi...

Sort is broken v6.2
When I try to sort my inbox by date I get a list that's mostly sorted but there are bunches of messages in the wrong place. Could this be because I have over ten thousand messages? The same thing happened on V5.0 so I moved up last month and the problem persists. Henry hjnoble@igc.org <hjnoble@igc.org> wrote in message news:1150837298.450606.283910@p79g2000cwp.googlegroups.com... > When I try to sort my inbox by date I get a list that's mostly sorted > but > there are bunches of messages in the wrong place. Could this be because > I have over ten...

pdftexlib for pdftex win32-bin
Hi everybody, (newbie problem) On http://www.tug.org/applications/pdftex/ we can get bin-pdftex-1.10b-win32-static.zip and also the user manual(pdftex-s.pdf). Now, if I want pdftex running without any Macro Tex distribution on my machine, I need the pdftexlib.zip... if I got it right from the user manual. Why, if I was to build the bin myself, it would give me pdftex.pool and texmf.cnf according to the user manual and that the bin package only contains pdftex.pool. Now, to get this working, I need the specific platform independent files(pdftex.cfg,*.enc, *.map, *.tex) which should be in th...

Sort-Problem
Hi, with the code below the output is sort by $verantw but $title and $file in the same row DON'T belong to $verantw. How do I have to make the sort command that $verantw, $title and $file in the row "belongs together"? Hope you understand my problem...... <?php $handle = opendir('.'); $daten = array(); $daten['files'] = array(); $daten['title_tags'] = array(); $daten['verantw'] = array(); while ($file = readdir($handle)) { if (substr($file, -4) == '.htm') { $daten['...

Re: A variable Sorting Problem #7
On Fri, 27 Jul 2007 06:55:44 -0000, nichas <sachin.gadkar@GMAIL.COM> wrote: > >data one; >input b d c a e; >datalines; >1 2 3 4 5 >3 4 3 2 1 >; >run; >proc sql; >select name >into :mvar separated by ' ' >from dictionary.columns >where libname='WORK' and memname='ONE' >order by name; >quit; >%put &mvar.; >data one; >retain &mvar.; >set one; >run; Nothing quite like jumping in late, reposting what's already said? Please read the thread prior to posting. That way, people don't have to re...

Sorting: 1 to 99
CLS REM ============================================================ REM To SORT any numbers 1 to 99; but no repeats. REM (This compares sort-numbers with Nos.1 to 99, REM and not with each other.) REM [You can't put a comment at end of DATA line, or it is REM regarded as data, by QBasic.] REM ============================================================ DIM a(1 TO 99), b(1 TO 99), c(1 TO 99) 'All ranges must be 99 PRINT "======= Store data in array ============================" N = 7 FOR X = 1 TO N READ a(X) PRINT a(X); NEXT X PRINT ...

Reading .bin in Fortran Mex
I'm working on updating a Fortran program to a mex routine and am having trouble reading a Fortran generated .bin file. I'm confident that I've set up the interface routine properly and the program works if I comment out the lines that handle the reading of the file. The Fortran code's pretty simple, it looks like: (parent function): OPEN (LSAVE, FILE='save.bin', STATUS='OLD', + FORM='UNFORMATTED', ERR=1 + ) the file pointer LSAVE is then passed to a subroutine which attempts the following: READ(LSAVE) input The mex routine crash...

Unix Sort?
Hi, I have a file and I want to extract all the lines that start with a number or letter, then sort those results, eliminating duplicates, and place them in an output file. I seem to have all the right parts, but cannot get them to work together: cat input.txt | grep '^[0-9][a-z][A-Z]' | sort -u > output.txt Any help? Thanks! 2007-02-21, 11:26(-08), amerar@iwc.net: > Hi, > > I have a file and I want to extract all the lines that start with a > number or letter, then sort those results, eliminating duplicates, and > place them in an output file. > > I seem...

Sorting
Is there a way in Pegasus to filter/search on either a flag or a colour. I have a number of emails some of which require action at some point in the future. What I'd like to do is file these emails in their respective folders and then do a search across all folders to find the flagged emails. Thanks Colin Colin a �crit : > Is there a way in Pegasus to filter/search on either a flag or a > colour. I have a number of emails some of which require action at some > point in the future. What I'd like to do is file these emails in their > respective folders and then ...

Sorting files recursively
Hi everyone, I would like to sort all files in a directory tree by modification time. I have tried `ls -ltR', but with that command the files are only sorted within each directory; I want a global sort. Any ideas? Regards, August On 3 Oct 2006 02:35:52 -0700, augukarl@yahoo.se wrote: > Hi everyone, > > I would like to sort all files in a directory tree by modification > time. I have tried `ls -ltR', but with that command the files are only > sorted within each directory; I want a global sort. Any ideas? [...] ls -ltd -- **/* (assuming your shell is zsh (or a rece...

Sorting atoms in a case-insensitive manner?
Is there any easy way to sort a list of atoms in a case-insensitive manner? predsort(compare, List, SortedList). sorts it like that: Aaaa BBbbb aaaa bbbb whereas I need Aaaa aaaa BBbbb bbbb Thanks for your kind help. -- Best Regards, Maurizio Colucci Please remove the uppercase letters "S,P,A,M": seSgPuAsMo.forever@tin.it In article <pan.2003.11.29.11.28.11.885516@in.signature>, seguso wrote: > > Is there any easy way to sort a list of atoms in a case-insensitive manner? > > predsort(compare, List, SortedList). > > sorts it like that: > >...

Sorting by Subject
Hi, How can I add a Sort option to the Subject field? I've R6.5 Thks. On 3 Jun 2004 07:21:27 -0700, sapmanie@excite.com (x) wrote: >Hi, > >How can I add a Sort option to the Subject field? I've R6.5 > >Thks. Is this a reasonable thing to do? Make it so "stray dog" is sorted so it appears a long way away from "dog", "re: stray doy" etc. Hi, I wouldn't have asked if I didn't need the feature. Is it possible? Thks. no.one@localhost wrote in message news:<gbsub0t913joqv4j2eitgkjbvdm00fevjj@4ax.com>... ...

Re: Proc sort Nodupkey..but I want to keep the first. (dot) of #3
You prescribed the tool as PROC SORT. If your dataset is large and if you don't really need to have output data in order of the key, that might be rather inefficient. 1 Data xx ; 2 Format keydt date. rcode $4. pcode $5. ; 3 Input ID keydt :date. rcode pcode pr ; 4 Cards4 ; NOTE: The data set WORK.XX has 39 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.85 seconds cpu time 0.01 seconds 44 ;;;; 45 Data deduped ; 46 Set xx ; 47 If ( _N_ eq 1 ) then do ; 48 Declare hash...

Sorting the colors in an image (3D matrix)
How would I sort an RGB image so that the (0,0,0) is in the Upper Lefthand side, say, and (255,255,255) is in the Bottom Right? In article <25877815.1187291275872.JavaMail.jakarta@nitrogen.mathforum.org>, mpalmer@lmi.net <mpalmer@lmi.net> wrote: >How would I sort an RGB image so that the (0,0,0) is in the Upper Lefthand side, say, and (255,255,255) is in the Bottom Right? I must admit that I don't see the point of doing this, but... sortedimage = ... reshape( sortrows(reshape(Image,size(Image,1)*size(Image,2),3)), ... size(Image,1), size(Image,2), 3) Example, l...

Re: Oil prices, and is it a conspiracy of sorts? #3
Ray, he recently mentioned that now he had heard of $4 a gallon. not from him: But the tax-payers fill up his vehicle so he really doesn't care. On Fri, 18 Jul 2008 09:51:33 -0500, Ray Shahan=20 <rshahan@REPUBLICTITLE.COM> wrote: ><snip> >I do not envy your lack of memory. It must be difficult finding your >socks >in the morning. ><snip> > >You're right, it is difficult these days to find my socks (even though >they're in the same drawer every morning) - thank goodness my wife's >there to help me!! > ...

/usr/bin/ld: cannot find -lICE
Hi During compilation of a program (gwyddion), the above occurs. I have in past successfully compiled it on my Debian etch system, but recently upgraded to xorg ver 7, and that was a fraught process. I do seem to have the library I need, but ld does not seem to know it : $file -L /usr/X11R6/lib/libICE.so /usr/X11R6/lib/libICE.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), stripped Any ideas ? Thanks. On Tue, 06 Jun 2006 22:13:45 -0400, Geico Caveman <spam@spam.invalid> wrote: > Hi > > During compilation of a program (gwyddion), the above occurs. I have...

string sort()
How could i possibly sort this my $mystring = "this" and make it look like my $mystring = "hist" Chris wrote: > How could i possibly sort this my $mystring = "this" > and make it look like my $mystring = "hist" $mystring = join '', sort split //, $mystring; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl Chris wrote: > How could i possibly sort this my $mystring = "this" > and make it look like my $mystring = "hist" Guessing here (one single example is not a very good way to d...

Re: Newbi at SAS
Hi Serge, Yes everything looks all right. But I suspect that SAS initially creates a scratch target file and copies that one to the destination file when ready and succeeded. I don't know the location of the intermediate scratch file, but it may be your temporary SAS directory. It means sufficient space has to be free there to contain a copy of the result. If there is not sufficient space the file possibly may be removed and still during the process you may get the error message that you report. Just a guess, maybe there is something quite different going on. But I would check this out a...

Sorting in reverse is not the same as sorting then reversing
Sorting in reverse does not give the same result as sorting then reversing. It's easiest to see with a key function: py> a = ['fox', 'dog', 'DOG', 'cat', 'ape'] py> b = a[:] py> a.sort(key=str.lower, reverse=True) py> b.sort(key=str.lower) py> b.reverse() py> a ['fox', 'dog', 'DOG', 'cat', 'ape'] py> b ['fox', 'DOG', 'dog', 'cat', 'ape'] Sorting in reverse keeps the initial order of any equal elements unchanged. Sorting, then rev...