TMin


The TMin function returns the minimum value found in a data collection. The collection can be a Lua array or a class object of type CImage, CArray, or CMatrix. To process a variable list of values and tables, use the slower VMin function. Also see the CStats:Min method.

Syntax

nMin, nIndex, nStatus = TMin( table )

nMin, nIndex, nStatus = TMin( CImage )

nMin, nIndex, nStatus = TMin( CArray )

nMin, nIndex, nStatus = TMin( CMatrix )

where

    table, CImage, CArray, or CMatrix contains the target data.

    nMax is the minimum value of the data.

    nIndex is the array index or image pixel location for the minimum value.

    nStatus is the success code from the calculation (non-zero on failure).).

  

All table types except for the CImage class use double precision real numbers with data type "double". The CImage class supports values ranging from byte to double plus other data types. Numeric values other than double can be processed by first converting the table to a CImage. Note that you do not have to assign or use the 2nd or 3rd return value.

If the data are a multi-dimensional CImage, the returned location does not account for higher dimensions. For example, if nIndex = 2450 and the image has 1000 columns (the first dimension), then the minimum value is at column 450 in row 3.

For a CMatrix, the returned value of nIndex can be difficult to untangle because the CMatrix does not require a fixed number of columns in each row.

The CStats:Min method also can be used to calculate the min value. Using the CStats class has the added ability to constrain the sample to a rectangular region of a CImage or CMatrix.

Examples

The following script returns the minimum value in a table of 1 million random numbers.

t = TRand( 1000000 )

-- create a table of numbers

v, n = TMin( t )

-- find the minimum

Printf("Min=%lg at %d\n", v, n )

-- list the minimum value and location

  

The next script returns the minimum value for pixels in a CImage.

V = AttachView( "CImageView" )

-- attach the topmost image window

Assert( V and V:Count() > 0 )

-- make sure an image window is on top

v = TMin( V:GetImage() )

-- find the minimum value in the CImage

Printf("Min=%lg\n", v )

-- list the minimum value

Related Topics

Table Functions

Variable Argument Functions

TMax

CStats class