comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: sorting column arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: sorting column arrays [message #49154] Fri, 30 June 2006 09:15
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
> The last line makes the sort in one go, since SORT doesn't guarantee
> anything about the order of identical elements. You might have to
> adjust the coefficients if your data has a wider range than the sample
> you show.

sort does indeed tend to jumble things up a little, but bsort does the
job right:
http://www.dfanning.com/tips/sort.html.

also, something like this should work....

IDL> d = $
IDL> [[4, 7, 0, 1], $
IDL> [3, 6, 2, 9],$
IDL> [2, 2, 0, 2],$
IDL> [42, 4, 2, 7],$
IDL> [256, 3, 0, 2],$
IDL> [34, 2, 1, 5]]
IDL>
IDL> s1 = bsort(d[1, *])
IDL> s2 = bsort(d[3, s1])
IDL> s3 = bsort(d[2, s1[s2]])
IDL> sd = d[*, s1[s2[s3]]]
IDL>
IDL> print, d, 'sorted by columns 2>3>1', sd
4 7 0 1
3 6 2 9
2 2 0 2
42 4 2 7
256 3 0 2
34 2 1 5
sorted by columns 2>3>1
4 7 0 1
2 2 0 2
256 3 0 2
34 2 1 5
42 4 2 7
3 6 2 9


Gianguido
Re: sorting column arrays [message #49158 is a reply to message #49154] Fri, 30 June 2006 05:30 Go to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
How about this (no loop):

v=lonarr(4,n_elements(array))
reads,strmid(array,4),v
print,v[*,sort(v[1,*]+v[2,*]/10.+v[0,*]/100.)]

The last line makes the sort in one go, since SORT doesn't guarantee
anything about the order of identical elements. You might have to
adjust the coefficients if your data has a wider range than the sample
you show.

regards,
Greg
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL's THIN function, with /PRUNE option
Next Topic: Problem when reading many HDF-EOS file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 13:35:50 PDT 2025

Total time taken to generate the page: 7.36057 seconds