Histogram VI
- Updated2025-01-28
- 4 minute(s) read
Histogram VI
Finds the discrete histogram of the input sequence X.

Inputs/Outputs
![]() X must contain at least one sample. If X is empty, the histogram is undefined, and the VI sets Histogram: h(x) and X Values to empty arrays and returns an error. ![]() intervals specifies the number of intervals, or bins, to use in the histogram and must be greater than 0. If intervals is less than or equal to 0, the histogram is undefined, and the VI sets Histogram: h(X) and X Values to empty arrays and returns an error. The default is 10. ![]() Histogram Graph displays the bar graph of the histogram of the input sequence X. The y-axis is the histogram count, and the x-axis is the histogram center values of the intervals (bins) of the histogram. ![]() Histogram: h(x) is the discrete histogram of the input sequence X. ![]() X Values is an array of the center values of the interval (bin) of the histogram. ![]() error returns any error or warning from the VI. You can wire error to the Error Cluster From Error Code VI to convert the error code or warning into an error cluster. |
The histogram is a frequency count of the number of times that a specified interval occurs in the input sequence. The width of the frequency bin is
delta_x = (max–min)/mwhere m is the requested number of bins. The centers of each bin are set according to the following equation:
center[i] = min + delta_x/2 + i * delta_x.Example
If the input sequence is
X = {0, 1, 3, 3, 4, 4, 4, 5, 5, 8}then the Histogram: h(x) of X for eight intervals is
h(X) = {h0, h1, h2, h3, h4, h5, h6, h7} = {1, 1, 0, 2, 3, 2, 0, 1}Notice that the histogram of the input sequence X is a function of X.
The VI calculates Histogram: h(x) as follows. The VI scans the input sequence X to determine the range of values in it. Then the VI establishes the interval width, Δx, according to the specified number of intervals,

where max is the maximum value found in the input sequence X, min is the minimum value found in the input sequence X, and m is the specified number of intervals.
Let χ represent the output sequence X Values, because the histogram is a function of X. The VI evaluates elements of c using
χi = min + 0.5Δx + iΔxfor i = 0, 1, 2, …, m – 1
The VI defines the ith interval to be the range of values from up to but not including,
Δi ∈ (χi – 0.5Δx, χi + 0.5Δx)for i = 0, 1, 2, …, m – 1
and defines the function to be

The function has unity value if the value of x falls within the specified interval. Otherwise it is zero. Notice that the interval Δi is centered about χi, and its width is Δx.
The last interval, Δm–1, is defined. In other words, if a value is equal to max, it is counted as belonging to the last interval.
Finally, the VI evaluates the histogram sequence H using

where hi represents the elements of the output sequence Histogram: h(x), and n is the number of elements in the input sequence X.
Examples
Refer to the following example files included with LabVIEW.
- labview\examples\Mathematics\Probability and Statistics\Statistics Solver.vi
- labview\examples\Mathematics\Probability and Statistics\Probability Density.vi
- labview\examples\Mathematics\Probability and Statistics\Noise Statistics.vi