CHistogram:Class Description

CHistogram:Calc


The Calc method computes the histogram of a data array.

Syntax

Table = CHistogram:Calc( Data )

Remarks

This function returns an array containing the histogram frequencies for the Data array. The histogram is dependent on the binning parameters that control the size of each bin and how many bins are used over what range of values. Several class methods are provided for setting the binning strategy. If you do not configure the binning strategy, then the histogram is computed using the full range of sample data values and a bin count that is the lesser of the square root of the number of sample points and 100.

Example

The following script computes and plots a histogram of 1 million Gaussian random numbers. The 4th line creates a nice x-axis that makes the distribution symmetrical about 0 and places the center of each bin at the x-coordinate of the bin. Since there are 1,000,000 values in the data sample and the histogram uses auto binning, the number of elements in the histogram array y will be 100 (see above).

H = CHistogram:new()

-- create a CHistogram object

v = GaussDev( 1000000 )

-- create 1,000,000 values

y = H:Calc( v )

-- compute the histogram

x = Index( H:GetBinCount(), H:GetMin()+H:GetBinWidth()/2, H:GetBinWidth() )

SteplinePlot( x, y, "Sigma's", "Frequency" )

-- plot the histogram

H:delete()

 

This script created the plot shown below.

gaussian_histo_2.png

Related Topics

CHistogram Class, SetBinAuto