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

Home » Public Forums » archive » Re: Finding the index of the median
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: Finding the index of the median [message #7258 is a reply to message #7252] Tue, 29 October 1996 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Dean Schulze <schulze@cassini.lpl.arizona.edu> writes:

> The median function will return the median value of an
> array. Is there anyway to obtain the index into the array
> of the median value? For example, if I find the median in an
> array of measured values how can I get the corresponding value
> from the companion noise array?

The easiest way is to use the WHERE function. Your code might
look something like this:

array = [3, 7, 2, 8, 15, 1]
noise = RANDOMU(seed, 6)

medianValue = MEDIAN(array)
index = WHERE(array EQ medianValue)

Print, noise(index)

Be aware that there can be multiple locations in your
array that are equal to the median value. The index that
is returned by the WHERE function will be an array of
all of those values.

Just a tip. The return value from the WHERE funcution
(if it finds something) is *always* an array, even if it
finds only one instance. If you are going to use that
return value as if it were a scalar value (e.g., as a counter
in a loop) be sure you subset it like this: index(0).

Yours,

David

--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Is there a cheap implementation of IDL
Next Topic: Re: Correction: 2D FFt

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

Current Time: Fri Oct 10 08:32:54 PDT 2025

Total time taken to generate the page: 0.88096 seconds