vectorbase::GetSubVector

Description

Get a subset of the vector.

Syntax

int GetSubVector( vectorbase & vbTarget, int c1 = 0, int c2 = -1 )

int GetSubVector(vectorbase& vbTarget, const vector<uint>& vnIndices)


Parameters

vbTarget
[output] The numeric type vector (for example, vector<double>, vector<int> and so on) containing returned subset.
c1
[input] Begining element index, default is 0 (0-based offset).
c2
[input] Ending element index (inclusive), default is -1 (upto and including last element).
vnIndices
[input] including the indices of the wanted cells of sub vector from source vector.

Return

Returns 0 on success and -1 on failure.

Examples

EX1

void vectorbase_GetSubVector_ex1()
{
vector vec1 = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
vector vec2;
vec1.GetSubVector(vec2, 2, 5);
for (int ii = 0; ii < vec2.GetSize(); ii++)
printf("%g ",vec2[ii]);
// Result:
//        vec2 = {0.3, 0.4, 0.5, 0.6}
}


EX2

void vectorbase_GetSubVector_ex2()
{
vector vec1 = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
vector vec2;
vector<uint> vn = {1, 3, 5, 7};
vec1.GetSubVector(vec2, vn);
for (int ii = 0; ii < vec2.GetSize(); ii++)
printf("%g ",vec2[ii]);
// Result:
//        vec2 = {0.2, 0.4, 0.6, 0.8}
}


Remark

Get a subset of this vector using specified 0-based element indices.