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 #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:

> David Fanning wrote:

>> 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.

> That is exactly why the WHERE() function won't work.
> I need to know which one of those locations is returned
> by the MEDIAN() function.

I have apparently not made myself clear. Let me try again.

Suppose this is your array of values:

array = [3, 2, 7, 8, 15, 1]

The median value is the number 7 located at the third
position in the array, i.e., at the index 2. We see this
by printing the value of the MEDIAN function.

medianValue = MEDIAN(array)
PRINT, medianValue

The number 7 is printed. What Dean wants is
the location in the array where the median value
is located.

I suggest he use the WHERE function, which returns
the index in the variable array where the medianValue
is located. Like this:

PRINT, WHERE(array EQ medianValue)

The number 2 is printed. This is the *index* into
the array where the median value (7) is located.

My point is that the median value can occur multiple
times in the array. For example:

array = [3, 2, 7, 8, 7, 15, 1]

So that what the WHERE function returns is a vector
of *all* the indices into the array where the median
value occurs. In this example, do this:

medianValue = MEDIAN(array)
PRINT, WHERE(array EQ medianValue)

The indices 2 and 4 are printed out.

This works, by the way, for multidimensional arrays.

Hope this clarifies.

David

*************************************************
* David Fanning, Ph.D.
* 2642 Bradbury Court, Fort Collins, CO 80521
* Phone: 970-221-0438 Fax: 970-221-4762
* E-Mail: davidf@dfanning.com
*
* Sometimes I go about pitying myself, and all along my
* soul is being blown by great winds across the sky.
* -- Ojibway saying
************************************************
[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: Wed Oct 08 17:56:09 PDT 2025

Total time taken to generate the page: 0.00421 seconds