hist (replaces THistogram)


The hist function returns the histogram of an array using the CHistogram class with default parameters.

Syntax

histogram_table = hist( tbl )

bullet.gif    tbl is the 1-dimensional array of sample points.

bullet.gif    histogram_table is the returned 1-dimensional array containing the histogram frequencies.

bullet.gif    On failure, nil is returned.

Remarks

This function expedites histogram calculation when you do not need to set specific histogramming parameters. The function uses the default settings of the CHistogram class, which include a bin count of 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. It also could be compacted into a single line by removing the return value h containing the table of histogram frequencies. Note in the example below that the hist function automatically chooses the number of bins for the data, and an x-axisarray must be created with the number of elements equal to the number of bins. This script shows how to do that.

h = hist( gaussdev(1000000) )

-- compute the histogram

nBins = h:GetBinCount()

-- use the automatic binning

nStart = h:GetMin()+h:GetBinWidth()/2

 

nStep = h:GetBinWidth()

 

x = series( nBins, nStart, nStep )

-- create an x axis

line( x, h )

-- make a line plot

Related Topics

CHistogram Class, Table and Array Functions, histplot, series, gaussdev

 


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