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

Home » Public Forums » archive » Mode????
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Mode???? [message #13993] Wed, 13 January 1999 00:00 Go to next message
RobertKehoe is currently offline  RobertKehoe
Messages: 1
Registered: January 1999
Junior Member
Hi there
I am trying to find an IDL function that returns the mode out of an array
of numbers anyone know a way of doing this. It strange that there does not
seem to be a function for this.
Rob.
--
The opinions expressed in this communication are my own and do not
necessarily reflect those of my employer.
Re: Mode???? [message #14075 is a reply to message #13993] Thu, 14 January 1999 00:00 Go to previous message
S Penzes is currently offline  S Penzes
Messages: 4
Registered: February 1998
Junior Member
RobertKehoe wrote:

> Hi there
> I am trying to find an IDL function that returns the mode out of an array
> of numbers anyone know a way of doing this. It strange that there does not
> seem to be a function for this.
> Rob.
> --
> The opinions expressed in this communication are my own and do not
> necessarily reflect those of my employer.

Hi,
If by "mode" you mean the number that occurs most frequently in a vector
then take a look at this piece of code. It comes from the very first "Widget
Programming" course (heck my manuals are all stamped DRAFT). It was put
forward as an example of a piece of code that would forego the use of loops.
To me it was a classic example and I periodically revive it to show what can be
done.

Hope this is what you were looking for.

Function Mode, Value
NumElements = N_ELEMENTS( Value )
SortedValue = [ Value( SORT( Value )),0]
SortedValue(NumElements)= NOT( SortedValue( NumElements-1 ))
ShiftedValue = SHIFT( SortedValue,1 )
RunLengths = WHERE( SortedValue NE ShiftedValue )
RunsShifted = SHIFT( RunLengths,1 )
MaxRun = MAX( Runlengths - RunsShifted, Index )
Mode = SortedValue( RunsShifted( Index ))
Return, Mode
End

IDL> input=[3,3,4,4,4,2,2,5,5,5,5]
IDL> print,mode(input)
5


--
Steven Penzes (Steven.nospamPenzes@dres.dnd.ca)
Note: remove "nospam" from Reply-To and .signature
Re: Mode???? [message #14077 is a reply to message #13993] Thu, 14 January 1999 00:00 Go to previous message
Vapuser is currently offline  Vapuser
Messages: 63
Registered: November 1998
Member
steinhh@ulrik.uio.no (Stein Vidar Hagfors Haugan) writes:


> Robert Kehoe wrote:
>
>> I am trying to find an IDL function that returns the mode out of
>> an array of numbers anyone know a way of doing this. It strange
>> that there does not seem to be a function for this.
>
> It would be (a lot!) easier to answer this question if you could
> explain what you mean by "returning the mode out of an array of
> numbers". But let me have one or two shots:
>
> If you mean the modulus of the numbers in an array, use the
> operator MOD, as in:
>
> answer = numbers mod 5 ;; Returns array "numbers" modulo 5
>
> If you mean the size of an array (mode out of an array, well
> could be..?) try the function size().
>
> Otherwise, please clarify.
>
> Stein Vidar

Perhaps he means the statistical mode, i.e. the most probable value.
I don't know any procedure that does this but someone has probably
written one. Check the links on Dave Fanning's web page
(http://www.dfanning.com/documents/idllinks.html).You may find it
there.

The simpleminded way would be to calculate the histogram, then take
the mode to be whatever value the maximum of the histogram was. This ignores
the possibility of a multi-modal distribution. But I did say
'simpleminded'

William
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Problem with IDL output files
Next Topic: Thanks to Bauer and Menakkis

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

Current Time: Fri Oct 10 00:11:41 PDT 2025

Total time taken to generate the page: 0.40080 seconds