median (replaces TMedian)


The median function returns the median of a 1-dimensional array, CImage, or list of numbers. The mediansdev function returns both the median and standard deviation. The array and list parameters must contain a mixture of numbers and strings that can be converted to numbers. This function is similar to the CStat:Median method but does not require calling new_stats() beforehand to create a CStats object. The related mediann and mediansdevn functions calculate the mean and standard deviation for a general table that may contain numbers, strings, named keys, and sub-tables.

Syntax

nMedian = median( Data )

bullet.gif    Data is a 1-dimensional array, list of numbers, or a CImage object.

bullet.gif    n1, n2, n3, ... are numbers or string values that can be converted to numbers.

bullet.gif    nMedian is the returned median of the data.

Remarks

The CImage class supports values ranging from byte to double plus other pixel types.

Examples

The following script returns the median of a table of 1 million random numbers.

t = random( 1000000 )

-- create a table of numbers

v = median( t )

-- find the median

Printf("Median=%lg\n", v )

-- list the result

  

The next script returns the median value for pixels inside a rectangle at the corner of a CImage.

V = AttachView( "CImageView" )

-- attach the topmost image window

Assert( V and V:Count() > 0 )

-- make sure an image window is on top

R = new_rect( 1, 20, 1, 40 )

-- rectangle for corner of image

v = median( V:GetImage(), R )

-- use the current image in the CImageView

Printf("Median=%lg\n", v )

-- list the result

  

The next example computes the median value of a list of numbers:

m = median( 5, 6, -2, -1, 4 }

-- find the median value

Printf("Median = %lg\n", m )

-- result: Median = 4

Related Topics

Table and Array Functions, mediansdev, mean, sdev, CImageView Class, CStats class


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.