histogram
Syntax
histogram(X, [bins=10], [range], [density=false], [weights])
Details
Compute the histogram of a dataset.
Arguments
X is a numeric vector indicating the input data.
bins (optional) is a positive integer or a strictly increasing numeric vector:
-
A positive integer specifies the number of bins of equal width. The default value is 10.
-
A numeric vector specifies the bin edges, including the rightmost edge.
range (optional) is a pair or a numeric vector of length 2, indicating the
lower and upper range of the bins. Values outside the range are ignored. The default
value is [X.min(), X.max()].
density (optional) is a boolean value:
-
false (default): the result will contain the number of samples in each bin.
-
true: the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1.
weights (optional) is a numeric vector of the same length as X, representing the weight of each sample. Note that when density is false, the return value is the weighted counts.
Return Value
A dictionary containing the following key-value pairs:
-
H: The values of the histogram. See density and weights for a description of the possible semantics.
-
edges: the bin edges.
Examples
X = [3,4,5,6,7,8,9]
bins = 3
histogram(X, bins)
/*
H->[2,2,3]
edges->[3,5,7,9]
*/X = [3,4,5,6,7,8,9]
bins = [3,6,9]
histogram(X, bins)
/*
H->[3,4]
edges->[3,6,9]
*/X = [3,4,5,6,7,8,9]
bins = [3,6,9]
range = [4,8]
histogram(X, bins, range)
/*
H->[2,3]
edges->[3,6,9]
*/X = [3,4,5,6,7,8,9]
bins = [3,6,9]
range = [4,8]
histogram(X, bins, range, true)
/*
H->[0.133333333333333,0.2]
edges->[3,6,9]
*/X = [3,4,5,6,7,8,9]
bins = [3,6,9]
weights = [2,2,5,5,1,2,3]
histogram(X, bins, , false, weights)
/*
H->[9,11]
edges->[3,6,9]
*/