CStats:Moment


The Moment method computes the n-th order moment about the mean of 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

nValue = CStats:Moment( table, nOrder )

nValue = CStats:Moment( CImage, nOrder )

nValue = CStats:Moment( CImage, nOrder, CRect )

nValue = CStats:Moment( CArray, nOrder )

nValue = CStats:Moment( CArray, nOrder, CRect )

nValue = CStats:Moment( CMatrix, nOrder )

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.

    nOrder is the order of the moment to be computed and is 0 or greater.

    nValue is the n-th order moment of the data. On failure, 0 is returned.

Examples

Suppose that CImage object I and CRect object R exist. The following script returns the value for 2nd Moment inside a rectangle on the image:

S = CStats:new()

-- create a CStats object

nMom = S:Moment( I, R, 2 )

-- returns the 2nd order moment

Printf("Moment=%lg\n", nMom )

-- list the results

The following script computes the 2nd moment for a table of numbers:

S = CStats:new()

-- create a CStats object

t = { 5, 6, 7, 8, 9, 10.5 }

-- create a table to measure

Printf("Moment=%lg\n", S:Moment(t,2) )

-- list the result

Related Topics

Median

CStats Class