vectorbase::Replace

Description

Threshold replace for a vector.


Replaces values at the supplied indices by one value

Syntax

BOOL Replace( double dThresholdVal, double dReplaceVal = 0, uint wBitwiseOption = 0 )

int Replace(vector<uint>& vn, double dVal)

Parameters

dThresholdVal
[input] Threshold value in condition to be compared with cells in vector
dReplaceVal
[input] Replacement value used when condition is TRUE
wBitwiseOption
[input] Combination of the following bits:
MATREPL_TEST_LESSTHAN, use Less Than in condition TEST
MATREPL_TEST_EQUAL, use Equal in condition TEST
MATREPL_TEST_GREATER, use Greater Than in condition TEST
MATREPL_USE_ABSOLUTE_VALUE_IN_TEST, use Absolute values, in condition TEST
MATREPL_KEEP_ORIGINAL_SIGN_WHEN_TEST_RESULT_IS_TRUE, keep original sign if condition TRUE ACTION
MATREPL_SET_TO_MISSING_VALUE_WHEN_TEST_RESULT_IS_FALSE Set to missing, value if condition FALSE ACTION

vn

[input] the vector of indices at which to change the value.

dVal
[input] the value to use for replacement.

Return

TRUE on successful exit or FALSE on failure.


0 if OK, otherwise a negative value.

Examples

EX1

void vectorbase_Replace_ex1()
{
        // fill column1 row 1-100 with 1-100
    Worksheet wks = Project.ActiveLayer();        
    Dataset aa(wks,0);
    aa.Data(1,100); 

        // fill column2 row 1-100 with 1-100
    Dataset bb(wks,1);        
    vector va = aa;
    
    // replace all values greater then 80 with missing values        
    va.Replace(80,get_missing_value(),MATREPL_TEST_GREATER);
    bb = va;
    
    // will see all rows after 80 become missing values
        for (int ii = 0; ii < bb.GetSize(); ii++)
        printf("%.1f  ",bb[ii]);

}

EX2

void vectorbase_Replace_ex2()
{
    vector va = {1,2,3,4,5,6,0.4,0.3};
    
    // replace the values equal to 2 with 0
    va.Replace(2,0,MATREPL_TEST_EQUAL);
    
    for (int ii = 0; ii < va.GetSize(); ii++)
        printf("%g  ",va[ii]);
    // Result data: 
    //                            va = {1,0,3,4,5,6,0.4,0.3};
}

EX3

void vectorbase_Replace_ex3()
{
        vector<int> vn = {1,2,3,4,5,6,7,8,9,0};
        vector<uint> vIndex = {-1, 1, 5, 8, 30, 26};
        
        int nRet = vn.Replace(vIndex,6);  
        for (int ii = 0; ii < vn.GetSize(); ii++)
            printf("%d ",vn[ii]);
        // Result data: 
        //        vn={1,6,3,4,5,6,7,8,6,0}
}

EX4

void vectorbase_Replace_ex4()
{
        Worksheet       wks = Project.ActiveLayer();
        if (!wks)
            return;
        
        Dataset         ds(wks, 1);
        if(!ds)
            return;
                ds.Data(1,32);         //fill row 1-32 in col(b) with row number
        vector<uint> vIndex = {-1, 1, 5, 8, 30, 26};
        int nRet = ds.Replace(vIndex, 7.5); // replace all indices with 7.5
}

Remark

See Labtalk command tReplace


Replaces values at the supplied indices by one value

See Also

DataRange::Replace

header to Include

origin.h