CStats:Median


The Median method computes the median and standard deviation for a data sample. The sample may be a Lua table or a class object of type CImage, CArray, or CMatrix. For CImage and CMatrix objects, an optional CRect object can be used to define the points used in the calculation.

Syntax

nMedian, nStdDev = CStats:Median( table )

nMedian, nStdDev = CStats:Median( CImage, )

nMedian, nStdDev = CStats:Median( CImage, CRect )

nMedian, nStdDev = CStats:Median( CArray )

nMedian, nStdDev = CStats:Median( CArray, CRect )

nMedian, nStdDev = CStats:Median( CMatrix )

where

    table is a lua table containing the data.

    CImage, CArray, and CMatrix are class objects containing the data to measure,

    CRect is a CRect rectangle object that defines the region to measure.

    nMedian and nStdDev are the median and standard deviation of the data. On failure, 0,0 is returned.

Examples

Suppose that CImage object I and CRect object R exist. The following script returns the median inside a rectangle on the image:

S = CStats:new()

-- create a CStats object

nMed = S:Median( I, R )

-- returns the median

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

-- list the results

The following script returns the median value and standard deviation for a table of data. Note that both results returned by Median are listed because it is the last argument for the Printf function:

S = CStats:new()

-- create a CStats object

t = { 4, 4, 2, 5, 6.4, -1.42, -12, 3.4 }

-- create some data in a table

Printf("Median=%lg +/- %lg\n", S:Median(t) )

-- list the results

Related Topics

Rank

CStats Class

TMedian