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

Home » Public Forums » archive » How to find second minimum elements in 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 to find second minimum elements in an array in IDL? [message #64735 is a reply to message #64677] Thu, 15 January 2009 09:36 Go to previous messageGo to previous message
Conor is currently offline  Conor
Messages: 138
Registered: February 2007
Senior Member
On Jan 14, 10:53 am, "mgal...@gmail.com" <mgal...@gmail.com> wrote:
> On Jan 14, 8:26 am, Hu <jha...@gmail.com> wrote:
>
>> Supposing that there is an array X=[9,2,3,5,1,6,8,4,7], how can I find
>> the first and second minimums (in this array are elements 1 and 2) in
>> this vector?
>
>> I use this to find the first minimum (element 1):
>
>> index = where(X eq min(X))
>> minimum_first=X[index]
>
>> But, how can i find the elements 2 ?
>> thanks
>
> For a general approach for finding the n smallest elements of an array
> (using HISTOGRAM and REVERSE_INDICES!), try:
>
> http://michaelgalloy.com/2006/06/02/finding-the-n-smallest-e lements-i...
>
> Mike
> --www.michaelgalloy.com
> Tech-X Corporation
> Associate Research Scientist

I was curious, so I checked out your routine Mike. It looks good but
one problem - a for loop! I'm pretty sure you can replace:

nCandidates = 0L
for bin = 0L, nBins - 1L do begin
nCandidates += h[bin]
if (nCandidates ge n) then break
endfor

with:

max( total( h, /cumulative ) < n, bin )

which should work because max will return the first maximum value. Of
course, I was too lazy to see if the max(total()) method is actually
faster (since it involves a couple different compuatations), but oh
well, sometimes laziness wins :)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Two Million Visitors!
Next Topic: Question relating to IDL wavelet methods

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

Current Time: Fri Oct 10 22:17:48 PDT 2025

Total time taken to generate the page: 0.00603 seconds