|
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 parameters must contain numbers or 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.
Whereas this function operates on a pure (indexed)
array, the slightly slower,
mediann and
mediansdevn functions calculate the median
value for a general table that may be a multi-dimensional array or
contain a mixture of numbers, strings, named keys, and
sub-tables.
Syntax
nMedian = median( Data )
Data is a
1-dimensional array, list of numbers, or a
CImage object.
n1,
n2, n3, ... are numbers or string values
that can be converted to numbers.
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 )
|
|
|
v = median( t )
|
|
|
Printf("Median=%lg\n", v )
|
|
The next script returns the median value for pixels
inside a rectangle at the corner of a
CImage.
|
V = AttachView( "CImageView"
)
|
|
|
Assert( V and V:Count() > 0
)
|
|
|
R = new_rect( 1, 20, 1, 40
)
|
|
|
v = median( V:GetImage(), R
)
|
|
|
Printf("Median=%lg\n", v )
|
|
The next example computes the median value of a
list of numbers:
|
m = median( 5, 6, -2, -1, 4 }
|
|
|
Printf("Median = %lg\n",
m )
|
|
Related Topics
Table and Array Functions
mediansdev
mean
sdev
CImageView Class
CStats class
Mira Pro x64 Script User's Guide, v.8.76 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.
|