2.2.3.19.3 vectorbase::Average

Description

Compute moving average

Syntax

void Average( vectorbase & vSource, int nLength, int nOption = EDGEPAD_NAN )

Parameters

vSource
[input] vectorbase object containing the source values
nLength
[input] Length of averaging window. If less than 1, then no averaging is performed.
nOption
[input] Boundry condition of moving average. Currently only EDGEPAD_NAN is supported.
Detail could refer to ocmath_adjave_smooth

Return

Examples

EX1

//Set average window nLength to 3. Change nWinLength to 2, 
//its result should be the same as nLength = 3
void vectorbase_Average_ex1(int nWinLength = 2)
{
    vector vec1 = {1, 3, 2, 6, 4};
    vector vec2;
 
    vec2.Average(vec1, nWinLength);		
    for( int i = 0; i < vec2.GetSize(); i++ )
        printf("%2d : %f\n", i, vec2[i]);
}
//Result: 
//0 : 1.000000		1 					//Only 1 in the average window, there is not data on the left. So no need to get the right data. 
//1 : 2.000000		(1+3+2)/3 = 2		//1, 3 in the average window. Get 1 and 2 beside 3.
//2 : 3.666667		(3+2+6)/3 = 3.66667 //1, 3, 2 in the average window. Get 1, 3, 2, 6, 4, But Length <= nLength+1. So 1&4 are dropped.
//3 : 4.000000		(2+6+4)/3 = 4		//3, 2, 6 in the average window. Get 3, 2, 6, 4, But only 4 one the right. So 3 is dropped.
//4 : 4.000000		4					//No data one the right. So no need to get the left data.

Remark

Compute moving average of elements in the vector.

See Also

Header to Include

origin.h