mean median

meansdev


The meansdev function returns the mean and standard deviation of a CImage, 1-dimensional array, or list of numbers. The mean function returns only the mean value. The array and list parameters must contain a mixture of explicit numbers and strings that can be converted to numbers. This function is similar to the CStat:Mean method but does not require calling new_stats() beforehand to create a CStats object. The mean function calculates only the mean of a 1-dimensional array, CImage, or list of numbers.

Whereas this function operates on a pure (indexed) array, the slightly slower meann and meansdevn functions calculate the mean and standard deviation for a general table that may be a multi-dimensional array or contain a mixture of numbers, strings, named keys, and sub-tables. Also see the mean function which returns only the mean value.

Syntax

nMean, nStdDev = meansdev( Data )

nMean, nStdDev = meansdev( n1, n2, n3, ... )

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    nMean is the mean of the data.

bullet.gif    nStdDev is the standard deviation of the data.

Remarks

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

Examples

The following script returns the mean and standard deviation of a table containing 1 million random numbers.

t = random( 1000000 )

-- create a table of numbers

v, s = meansdev( t )

-- find the mean & standard deviation

Printf("Mean=%lg, sdev=%lg\n", v, s )

-- list the result

  

The next script returns the mean and standard deviation 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, s = meansdev( V:GetImage(), R )

-- use the current image in the CImageView

Printf("Mean=%lg, Sdev=%lg\n", v, s )

-- list the result

  

The next example computes the mean and standard deviation of a list of numbers:

v, s = meansdev( 5, 6, -2, 5.4 }

-- find the mean and standard deviation

Printf("M= %lg, S= %lg\n", v, s )

-- result: Mean = 3.6

Related Topics

Table and Array Functions

mean

meann

meansdevn

median

mediansdev

sdev

CImageView Class

CStats class

 


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