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

Home » Public Forums » archive » Re: Ordered index array
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: Ordered index array [message #45443 is a reply to message #45433] Wed, 07 September 2005 10:17 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> How about this:
>
> PRO TEST
> a = [3,6,2,1,2,7,1,1]
> h = Histogram(a, Reverse_Indices=ri, Min=0)
> b = Indgen(N_Elements(h)) + 1
> c = Intarr(N_Elements(h))
> FOR j=0,N_Elements(h)-1 DO BEGIN
> IF ri[j+1] NE ri[j] THEN $
> c[ri[ri[j]:ri[j+1]-1]] = Min(b[ri[ri[j]:ri[j+1]-1]])
> ENDFOR
> Print, c
> END
>
> 1 2 3 4 3 6 4 4
>
> Note that your original example is wrong. :-)

Whoops! *I* didn't use the original example either (although
yours is still wrong!).

Here is a more complete solution, using the original data:

PRO TEST
a = [3,6,2,1,2,8,1,1]
h = Histogram(a, Reverse_Indices=ri, Min=0)
b = Indgen(N_Elements(h)) + 1
c = Intarr(N_Elements(h))
FOR j=0,N_Elements(h)-1 DO BEGIN
IF ri[j+1] NE ri[j] THEN $
c[ri[ri[j]:ri[j+1]-1]] = Min(b[ri[ri[j]:ri[j+1]-1]])
ENDFOR
Print, c[0:N_Elements(a)-1]
END

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: 2 arrays, average, missing data
Next Topic: Re: 2 arrays, average, missing data

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

Current Time: Sat Oct 11 07:08:59 PDT 2025

Total time taken to generate the page: 1.27535 seconds