|
Re: How to find second minimum elements in an array in IDL? [message #64672 is a reply to message #64671] |
Wed, 14 January 2009 07:41  |
Hu
Messages: 35 Registered: January 2009
|
Member |
|
|
On Jan 14, 10:31 am, David Fanning <n...@dfanning.com> wrote:
> Hu writes:
>> 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 ?
>
> Set the first minimum elements to some absurdly large
> value and give it another try. :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
thank you, David ! It works!
I surf your website everyday.
|
|
|
|
Re: How to find second minimum elements in an array in IDL? [message #64675 is a reply to message #64672] |
Wed, 14 January 2009 07:38  |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
or something like,
IDL> X=[9,2,3,5,1,6,8,4,7]
IDL> ind1 = where(X eq min(X), comp=comp)
IDL> ind2 = where(x[comp] eq min(x[comp]))
IDL> print, x[ind1], x[ind2]
1
2
be VERY careful that ind2 is referring to the array x[comp] NOT the
array x.
Or one could use sort to find the value:
IDL> xs=x[sort(x)]
IDL> xu=uniq(xs)
% Compiled module: UNIQ.
IDL> ind=where(xu eq 1)
IDL> print, xu[1]
1
and there where to find the index of the value in x
Cheers,
Brian
------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
|
|
|
Re: How to find second minimum elements in an array in IDL? [message #64676 is a reply to message #64675] |
Wed, 14 January 2009 07:31  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Hu writes:
> 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 ?
Set the first minimum elements to some absurdly large
value and give it another try. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|