VMean


The VMean function returns the mean and standard deviation for a variable list that can include values, tables, and data collection objects. If the list consists only of a single large table or class object, use the faster TMean function.

Syntax

nMean, nSdev = VMean( ... )

where

    ... is a list of numbers, tables, CImage, CArray, and CMatrix objects.

    nMean is the mean value for all items in the list.

    nSdev is the standard deviation of all items in the list.

  

To process a single table, or a single CImage, CArray, or CMatrix object, use TMean function or the CStats:Mean method. Using the CStats class has the added ability to constrain the sample to a rectangular region of a CImage. CArray, or CMatrix object. Since Lua implicitly converts string representations of numbers to numbers, the argument list and tables also may contain strings that can be converted to numbers.

Example

The following script returns the mean and standard deviation of values in a collection of tables and numbers. Note that table t is used twice in the argument list just for testing purposes.

t0 = { 1.5e-4, 2, 3, 4 }

-- create atable

t1 = { 10, 11 }

-- create another table

t2 = { {26, t0}, {"27"}, 3 }

-- createsome subtables

t3 = { 4, "5", "6" }

-- create a table with strings as numbers

t = { t1, t2, t3 }

-- assemble tables into another table

m, s = VMean( t, 2, 5, t, "6" )

-- call VMean() with an argument list

Printf( "Mean = %lg +/- %lg\n", m, s )

-- Result: Mean = 7.96297 +/- 8.40091

Related Topics

Variable Argument Functions

Table Functions

TMean

CStats class