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

Home » Public Forums » archive » Re: How do you sort an array in IDL?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How do you sort an array in IDL? [message #11487 is a reply to message #11484] Thu, 02 April 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Robert A. Lematta (lematta@nosc.mil) writes:

> Does anyone know how to sort an array in idl (ala excell) while preserving
> the order of the other columns.

Here is a little example in which a two-column array is
sorted by the values in the second column, it can
easily be converted to a function that returns an
array sorted by any column.

Cheers,

David

-----------------------------------------------------------

PRO SortColumn

; Create example data.

array = FltArr(2, 10)
array[0,*] = IndGen(10) + 1 ; Number
array[1,*] = RandomU(seed, 10) * 10 ; Value

Print, 'Unsorted Array---'
Print, array
Print, ''

; Sort the data by value.

sortIndex = Sort(array[1,*])
sortedArray = FltArr(2,10)
FOR j=0,1 DO sortedArray[j,*] = (array[j,*])[sortIndex]

Print, 'Array Sorted by Value---'
Print, sortedArray
Print, ''

END

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Write-mask problem with "win" device?
Next Topic: drawing a shaded sphere

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

Current Time: Thu Oct 16 01:43:24 PDT 2025

Total time taken to generate the page: 0.80201 seconds