2.2.3.9.33 matrixbase::GetMean

Description

Get the mean cell value of the matrix (as a double).

Syntax

double GetMean( )

Parameters

Return

Returns the mean cell value of the matrix (as a double).

Note that the missing values (NANUMs) in the matrix are ignored in computation.

Examples

EX1

// Compute the mean value of cells of a matrix
void matrixbase_GetMean_ex1()
{
    matrix<double> mat1 = {
        {1,  1,  1,  1},
        {2,  4,  6,  8},
        {3,  6,  9, 12}
    };
    // Output of this program will be like following:
    //   The mean value of cells in Matrix1 is: 4.5 .
    
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    Mat1 = mat1;
    
    double dMean;
    dMean = Mat1.GetMean();  // Compute the mean value by GetMean
    printf("  The mean value of cells in %s is: %g .\n",
      Mat1.GetName(), dMean);
}

EX2

// Compute the mean value of cells of a matrix including NANUMs
void matrixbase_GetMean_ex2()
{
    matrix<double> mat1 = {
        {99, 99, 99},
        { 2,  3,  4}
    };
    mat1[0][0]=NANUM;  // set row=1,col=1 to NANUM
    mat1[0][1]=NANUM;  // set row=1,col=2 to NANUM
    mat1[0][2]=NANUM;  // set row=1,col=3 to NANUM
    // Input matrix is:
    //  {--, --, --}
    //  { 2,  3   4}
    //
    // Output of this program will be like following:
    //   The mean value of cells in Matrix1 is: 3 .
    
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    Mat1 = mat1;

    double dMean;    
    dMean = Mat1.GetMean();  // Compute the mean value by GetMean
    printf("  The mean value of cells in %s is: %g .\n",
      Mat1.GetName(), dMean);
}

Remark

Get the mean value of the matrix (as a double).

See Also

matrixbase::GetMedian, matrixbase::GetMin, matrixbase::GetMax

Header to Include

origin.h