2.2.3.9.57 matrixbase::ReplaceLessThan

Description

Replace all cell values less than dThresholdVal with dReplaceVal.

Syntax

BOOL ReplaceLessThan( 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_ReplaceLessThan_ex1()
{
    BOOL rc;

    matrix<double> mat1 = {
        {-2.0,   0.05, 0.1, 2},
        {-0.1,  10,   10,  10},
        {-0.05, 10,   10,  10},
        { 2,    10,   10,  10}
    };
    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.ReplaceLessThan(0.1, 0.0); // Demonstrate  ReplaceLessThan
    // Result matrix:
    //    {0,  0, 0.1, 2},
    //    {0, 10, 10, 10},
    //    {0, 10, 10, 10},
    //    {2, 10, 10, 10}
        
    if(!rc) printf("Error: ReplaceLessThan(0.1, 0.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 ReplaceLessThan (<0.1) matrix in %s.\n",
          Mat2.GetName());
    }
    
    matrix mat3(mat1);  // Create mat2, and copy mat1 to mat2
    rc=mat3.ReplaceLessThan(-0.1, 0.0); // Demonstrate  ReplaceLessThan
    // Result matrix:
    //    { 0,     0.05, 0.1, 2},
    //    {-0.1,  10,   10,  10},
    //    {-0.05, 10,   10,  10},
    //    { 2,    10,   10,  10}
        
    if(!rc) printf("Error: ReplaceLessThan(-0.1, 0.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 ReplaceLessThan (<-0.1) matrix in %s.\n",
          Mat3.GetName());
    }            
}

Remark

Replace all cell values less than dThresholdVal with dReplaceVal.

See Also

matrixbase::Replace, matrixbase::ReplaceGreaterThan

Header to Include

origin.h