hist(v,e)

hist(v, e) -> e, counts

Compute the histogram of v using a vector/range e as the edges for the bins. The result will be a vector of length length(e) - 1, such that the element at location i satisfies sum(e[i] .< v .<= e[i+1]). Note: Julia does not ignore NaN values in the computation.

Examples

  1. Compute histogram with default number of bins:

    julia> v = [1, 2, 1, 3, 2, 4, 1, 2, 3];
    julia> e, counts = hist(v)
    ([1, 2, 3, 4], [3, 3, 2])

    This example computes the histogram of the vector v using the default number of bins. It returns the range e which represents the edges of the bins, and counts which contains the count of elements in each bin.

  2. Compute histogram with a specific number of bins:

    julia> v = [1.5, 2.7, 3.8, 4.9, 5.5];
    julia> e, counts = hist(v, 3)
    ([1.5, 3.0, 4.5, 6.0], [1, 1, 3])

    This example computes the histogram of the vector v using 3 bins. It returns the range e with the bin edges and counts with the count of elements in each bin.

  3. Handle NaN values in the computation:
    julia> v = [1, 2, NaN, 3, 4, NaN, 5];
    julia> e, counts = hist(v)
    ([1.0, 2.0, 3.0, 4.0, 5.0], [1, 1, 1, 1, 1])

    The hist function does not ignore NaN values in the computation. It treats them as separate elements in the histogram.

Common mistake example:

julia> v = [1, 2, 3, 4, 5];
julia> e, counts = hist(v, -2)
ERROR: ArgumentError: number of bins must be non-negative

In this example, a negative number of bins is provided, which is not allowed. Ensure that the number of bins is a non-negative integer when using the hist function.

See Also

cummax, eigmax, findmax, hist, hist!, hist2d, hist2d!, histrange, indmax, maxabs, maxabs!, maximum!, mean, mean!, median, median!, minabs, minabs!, minimum!, minmax, quantile!, realmax, std, stdm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: