Threshold replace for a vector.
Replaces values at the supplied indices by one value
BOOL Replace( double dThresholdVal, double dReplaceVal = 0, uint wBitwiseOption = 0 )
int Replace(vector<uint>& vn, double dVal)
[input] the vector of indices at which to change the value.
TRUE on successful exit or FALSE on failure.
0 if OK, otherwise a negative value.
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 }
See Labtalk command tReplace
Replaces values at the supplied indices by one value
origin.h