CHistogram:Calc


The Calc method computes the histogram of a 1-dimensional array.

Syntax

tTable = CHistogram:Calc( Data )

bullet.gif    tData is the input data 1-dimensional array containing the data.

bullet.gif    tTable is a 1-dimensional array containing the histogram frequencies.

Remarks

The computed histogram is dependent on the binning parameters which control the "size" of each bin and number of bins used over the range of data 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 equal to the square root of the number of sample points.

One reason to use this class and method rather than the Histogram function is that the class provides access to the actual binning parameters used after the histogram is calculated in "Auto" mode (the default or set using the SetBinAuto method).

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 = new_histogram

-- create a CHistogram object

v = gaussdev( 1000000 )

-- create 1,000,000 values

y = H:Calc( v )

-- compute the histogram

nCount = H:GetBinCount()

-- separate the 3 parameters for clarity

nMin = H:GetMin()+H:GetBinWidth()/2

 

nStep = H:GetBinWidth()

 

x = series( nCount, nMin, nStep )

-- create a series for the histgram x axis

stepline( 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, series, gaussdev, plot, Histogram


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.