2.2.3.9.56 matrixbase::ReplaceGreaterThanReplaceGreaterThan
Description
Replace all cell values greater than dThresholdVal with dReplaceVal.
Syntax
BOOL ReplaceGreaterThan( double dThresholdVal, double dReplaceVal )
Parameters
- dThresholdVal
- [input] Condition or threshold value
- dReplaceVal
- [input] Replacement value
Return
Returns TRUE on success or FALSE on failure.
Examples
EX1
void matrixbase_ReplaceGreaterThan_ex1()
{
BOOL rc;
matrix<double> mat1 = {
{-2.0, 0.05, 0.1, 2},
{-0.1, 0, 0, 0},
{-0.05, 0, 0, 0},
{ 2, 0, 0, 0}
};
MatrixPage MatPg1;
MatPg1.Create("Origin");
MatrixLayer MatLy1 = MatPg1.Layers(0);
Matrix Mat1(MatLy1);
Mat1 = mat1;
printf(" The original matrix is %s.\n",Mat1.GetName());
matrix mat2(mat1); // Create mat2, and copy mat1 to mat2
rc=mat2.ReplaceGreaterThan(0.1, 10.0); // Demonstrate ReplaceGreaterThan
// Result matrix:
// {-2.0, 0.05, 0.1, 10},
// {-0.1, 0, 0, 0},
// {-0.05, 0, 0, 0},
// {10, 0, 0, 0}
if(!rc) printf("Error: ReplaceGreaterThan(0.1, 10.0) on a matrix failed.\n");
else
{
MatrixPage MatPg2;
MatPg2.Create("Origin");
MatrixLayer MatLy2 = MatPg2.Layers(0);
Matrix Mat2(MatLy2);
Mat2 = mat2;
printf(" Observe the ReplaceGreaterThan (>0.1) matrix in %s.\n",
Mat2.GetName());
}
matrix mat3(mat1); // Create mat2, and copy mat1 to mat2
rc=mat3.ReplaceGreaterThan(-0.1, 10.0); // Demonstrate ReplaceGreaterThan
// Result matrix:
// {-2, 10, 10, 10},
// {-0.1, 10, 10, 10},
// {10, 10, 10, 10},
// {10, 10, 10, 10}
if(!rc) printf("Error: ReplaceGreaterThan(-0.1, 10.0) on a matrix failed.\n");
else
{
MatrixPage MatPg3;
MatPg3.Create("Origin");
MatrixLayer MatLy3 = MatPg3.Layers(0);
Matrix Mat3(MatLy3);
Mat3 = mat3;
printf(" Observe the ReplaceGreaterThan (>-0.1) matrix in %s.\n",
Mat3.GetName());
}
}
Remark
Replace all cell values greater than dThresholdVal with dReplaceVal.
See Also
matrixbase::Replace, matrixbase::ReplaceLessThan
Header to Include
origin.h
|