Calculate median value.

Namespace:  AForge.Math
Assembly:  AForge.Math (in AForge.Math.dll) Version: 2.2.5.0 (2.2.5.0)

Syntax

C#
public static int Median(
	int[] values
)

Parameters

values
Type: array< System..::.Int32 >[]()[]
Histogram array.

Return Value

Returns value of median.

Remarks

The input array is treated as histogram, i.e. its indexes are treated as values of stochastic function, but array values are treated as "probabilities" (total amount of hits).

Note:The median value is calculated accumulating histogram's values starting from the left point until the sum reaches 50% of histogram's sum.

Sample usage:

CopyC#
// create histogram array
int[] histogram = new int[] { 1, 1, 2, 3, 6, 8, 11, 12, 7, 3 };
// calculate median value
int median = Statistics.Median( histogram );
// output it (6)
Console.WriteLine( "median = " + median );

See Also