vectorbase::GetMinMax

Description

Get min and max values and their indices from the vector.

Syntax

int GetMinMax( double & min, double & max, int * pIndexMin = NULL, int * pIndexMax = NULL )

Parameters

min
[output] minimum value of all elements in vector.
max
[output] maximum value of all elements in vector.
pIndexMin
[output] the pointer of the index of minimum value
pIndexMax
[output] the pointer of the index of maximum value

Return

The number of elements in the vector that are not missing values (NANUM). If all elements of the vector are missing values, min(max) cannot be computed and then *pIndexMin and *pIndexMax will return -1. For vectors of type complex, if either of real and imaginary part is missing value, the amplitude will be a missing value.

Examples

EX1

//This example shows GetMinMax in the vector with missing value
void vectorbase_GetMinMax_ex1()
{
    vector vec1 = {5, 6, 1, 2, 3, 4};
    vec1[3] = NANUM;
    double dMin, dMax;
    uint nIndexMin, nIndexMax, nCountNonMissingValues;
    // Call method to compute quantities
    nCountNonMissingValues = vec1.GetMinMax(dMin, dMax, &nIndexMin, &nIndexMax);
    printf("dMin = %.0f\ndMax = %.0f\nnIndexMin = %d\nnIndexMax = %d\nnCountNonMissingValues = %d\n",
                dMin,dMax,nIndexMin,nIndexMax,nCountNonMissingValues);
    // Result:
    //        dMin = 1
    //        dMax = 6
    //        nIndexMin = 2
    //        nIndexMax = 1
    //        nCountNonMissingValues = 5
}

EX2

// Call this function with a worksheet active, which has some data. 
// The example shows GetMinMax from the worksheet.

void vectorbase_GetMinMax_ex2()
{
        Worksheet wks = Project.ActiveLayer(); 
    foreach( Column col in wks.Columns )
    {
        Dataset ds(col);
        double min, max;
        int imin, imax;
        ds.GetMinMax(min, max, &imin, &imax);
        // Show row index in LabTalk convention of 1-offset
        printf("Col(%s): max[%d] = %f, min[%d] = %f\n", col.GetName(), imax+1, max, imin+1, min);
    }
}

Remark

Get the min, max and their associated indices from the vectorbase object. For vectorbase objects of type complex, the amplitude will be used to determine the min and max.

See Also

ocmath_d_minmax

header to Include

origin.h