hist(x) creates a
histogram bar chart of the elements in vector x.
The elements in x are sorted into 10 equally spaced
bins along the x-axis between the minimum and
maximum values of x. hist displays
bins as rectangles, such that the height of each rectangle indicates
the number of elements in the bin.

If the input is a multi-column array, hist creates
histograms for each column of x and overlays them
onto a single plot.

If the input is of data type categorical,
each bin is a category of x.

hist(x,xbins) sorts x into
bins with intervals or categories determined by the vector xbins.

If xbins is a vector of evenly
spaced values, then hist uses the values as the
bin centers.

If xbins is a vector of unevenly
spaced values, then hist uses the midpoints between
consecutive values as the bin edges.

If x is of data type categorical,
then xbins must be a categorical vector or cell
array of strings that specifies categories. hist plots
bars only for those categories.

The length of the vector xbins is
equal to the number of bins.

hist(ax,___) plots
into the axes specified by ax instead of into the
current axes (gca). The option ax can
precede any of the input argument combinations in the previous syntaxes.

counts = hist(___) returns
a row vector, counts, containing the number of
elements in each bin.

Generate three columns of 1,000 random numbers and plot the three column overlaid histogram.

x = randn(1000,3);
hist(x)

The values in x are sorted among 10 equally spaced bins between the minimum and maximum values. hist sorts and bins the columns of x separately and plots each column with a different color.

Plot three histograms of the same data using different bin intervals:

In the upper subplot, specify the bin centers using a vector of evenly spaced values that span the values in x.

In the middle subplot, specify the bin centers using a vector of evenly spaced values that do not span the values in x. The first and last bins extend to cover the minimum and maximum values in x.

In the lower subplot, specify the bin intervals using a vector of unevenly spaced values. The hist function uses the midpoints between consecutive values as the bin edges and indicates the specified values by markers along the x-axis.

Create a figure with two subplots. In the upper subplot, plot a histogram of 1,000 random numbers sorted into 50 equally spaced bins. In the lower subplot, plot a histogram of the same data and use bins with centers at -3, 0, and 3.

If x is a vector, then hist creates
one histogram.

If x is a matrix, then hist creates
a separate histogram for each column and plots the histograms using
different colors.

If the input array contains NaNs or undefined
categorical values, hist does not include these
values in the bin counts.

If the input array contains the infinite values -Inf or Inf,
then hist sorts -Inf into the
first bin and Inf into the last bin. If you do
not specify the bin intervals, then hist calculates
the bin intervals using only the finite values in the input array.

Bin locations or categories, specified as a vector.

If x is numeric or logical, then xbins must
be of type single or double.

If the elements in xbins are
equally spaced, then these elements are the bin centers.

If the elements in xbins are
not equally spaced, then these elements are indicated by markers along
the x-axis, but are not the actual bin centers.
Instead, hist calculates the bin edges as the midpoints
between consecutive elements in vector xbins.
To specify the bin edges directly, use histc.

xbins must contain only finite
values. The first and last bins extend to cover the minimum and maximum
values in x.

If x is categorical, then xbins must
be a categorical vector or cell array of strings that specifies categories. hist plots
bars only for those categories specified by xbins.

Bin centers or categories, returned as a vector. If used with
the syntax [counts,centers] = hist(x,xbins), then
the centers output has the same elements as the xbins input.

If x is numeric or logical, then centers is
a numeric row vector.

If x is categorical, then centers is
a cell array of strings.