CStats:Mean and CStats:MeanSdev


The Mean method computes the mean and standard deviation of a 1-dimensional array, CImage, or list of numbers. The array and list parameters must contain a mixture of numbers and strings that can be converted to numbers.

Syntax

nMean = CStats:Mean( CImage, CRect )

nMean = CStats:Mean( CImage )

nMean = CStats:Mean( table )

nMean = CStats:Mean( n1, n2, n3, ... )

nMean, nSdev = CStats:MeanSdev( CImage, CRect )

nMean, nSdev = CStats:MeanSdev( CImage )

nMean, nSdev = CStats:MeanSdev( table )

nMean, nSdev = CStats:MeanSdev( n1, n2, n3, ... )

bullet.gif    CRect is a bounding rectangle for the CImage object.

bullet.gif    table is a 1-dimensional array containing numbers.

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

bullet.gif    On success, the mean and standard deviation are returned.

bullet.gif    On failure, returns 0, 0.

Remarks

Although this method returns two values, the mean and the standard deviation, you do not have to assign a variable to capture the standard deviation in the second returned value. For example,

tbl = {}

-- create a table and fill it with values

S = new_stats()

 

m = S:Mean( tbl )

-- get the mean of table T.

m, sd = S:MeanSdev( tbl )

-- gets the mean and standard deviation of the 1-dimensional array.

If Mean is the last function in an expression, both return value can be captured as shown in this example:

     Printf( "%lg +/- %lg, S:Mean(tbl) ).

There also are global functions mean and sdev that compute the mean and standard deviation without using CStats class to be invoked in the script.

Example

Suppose a CImage I exists. The following script returns the mean and standard deviation of 600 pixels in the corner of the image, starting at column,row = (5,8). This example shows how the parameter list with a mixture values and explicit numbers:

S = new_stats()

-- create a CStats object

k = 20; p = 30

 

m, sd = S:MeanSdev( I, CRect:new( 5,k+5,8,p+8 )

-- computes values inside the CRect

Printf("mean=%lg +/- %lg\n", m, sd )

-- list the result

S:delete()

-- when done with S, delete it

Related Topics

CStats class, CImage class, CRect class, mean, sdev, Stats, Skewness, Kurtosis


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