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 #11484 is a reply to message #11423] Thu, 02 April 1998 00:00 Go to previous messageGo to previous message
Robert S. Hill is currently offline  Robert S. Hill
Messages: 11
Registered: January 1998
Junior Member
On Thu, 2 Apr 1998, Robert A. Lematta wrote:
> Does anyone know how to sort an array in idl (ala excell) while preserving
> the order of the other columns. For example, if I have a 10 by 10 array
> with the second column being time, how do I sort the entire array by time and
> have the values in the other columns follow. Like you'd do a sort in a
> spreadsheet. Please reply to lematta@spawar.navy.mil. Many thanks in advance.
> I've tried to figure out the sort function but I don't think it works on arraysswith more than one row or column.

You can do it with IDL's clever subscripting syntax:

Set up test data:

IDL> a = reverse(indgen(10))
% Compiled module: REVERSE.
IDL> b=indgen(10)+100
IDL> arr = transpose([[a],[b]])
IDL> print,arr
9 100
8 101
7 102
6 103
5 104
4 105
3 106
2 107
1 108
0 109

Sort on column 0:

IDL> col = arr(0,*)
IDL> s=sort(col)
IDL> arr2 = arr(*,s) ; sort on column, but apply sort to rows
IDL> print,arr2 ; voila
0 109
1 108
2 107
3 106
4 105
5 104
6 103
7 102
8 101
9 100

Bob

--
Robert.S.Hill.1@gsfc.nasa.gov Phone: 301-286-3624
Raytheon STX / Code 681, NASA/GSFC, Greenbelt, MD 20771
[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 20:48:35 PDT 2025

Total time taken to generate the page: 1.04128 seconds