2.2.3.9.34 matrixbase::GetMedianGetMedian
Description
Get the median cell value of the matrix (as a double). If there are an even
number N of cells in the matrix the average of the N/2 and (N+1)/2 sorted
cell values is returned.
Syntax
double GetMedian( )
Parameters
Return
Returns the median cell value of the matrix (as a double).
Examples
EX1
// Compute the median value of cells of a matrix
void matrixbase_GetMedian_ex1()
{
matrix<double> mat1 = {
{1, 1, 1},
{2, 3, 4}
};
// Output of this program will be like following:
// The median value of cells in Matrix1 is: 1.5 (=(1+2)/2) .
MatrixPage MatPg1;
MatPg1.Create("Origin");
MatrixLayer MatLy1 = MatPg1.Layers(0);
Matrix Mat1(MatLy1);
Mat1 = mat1;
double dMedian;
dMedian = Mat1.GetMedian(); // Compute the median value by GetMedian
printf(" The median value of cells in %s is: %g .\n",
Mat1.GetName(), dMedian);
}
EX2
// Compute the median value of cells of a matrix including NANUMs
void matrixbase_GetMedian_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 median value of cells in Matrix1 is: 1 .
MatrixPage MatPg1;
MatPg1.Create("Origin");
MatrixLayer MatLy1 = MatPg1.Layers(0);
Matrix Mat1(MatLy1);
Mat1 = mat1;
double dMedian;
dMedian = Mat1.GetMedian(); // Compute the median value by GetMedian
printf(" The median value of cells in %s is: %g .\n",
Mat1.GetName(), dMedian);
}
Remark
Get the median cell value of the matrix (as a double). And when computing, NANUM is seen as 0.
See Also
matrixbase::GetMean, matrixbase::GetMin, matrixbase::GetMax
Header to Include
origin.h
|