Categories

# Histogram in Matlab

Histogram is a representation of any statistical information showing the frequency of data items in successive intervals. MATLAB supports plotting histogram feature that enables the user to create a bar graph for any vector or matrix and grouping the data into bins using an automatic binning algorithm. For each bin, the area represents the frequency of occurrence of the data, not the height. It supports customization in histogram presentation.

## Syntax:

In earlier versions, hist() and histc() were used to generate histogram plots. In later versions those functions are replaced with new functions with advanced capabilities i.e. histogram(), histcounts() and discretize().

The syntax for the above-recommended functions are as follows:

• histogram(X, a1,a2,…..,an)
• histcounts(X, a1,a2,…..,an)
• discretize(X, a1,a2,…..,an)

Where X: Data input in the form of vector or matrix.

a1,a2,…..,an: Attribute values (optional)

Creation of Histogram in Matlab: MATLAB makes it a single click action to create a histogram for any data. A histogram can be created by using the inbuilt function histogram().

## Example:

The below code is written to generate 100 random numbers and histogram() is used to plot a histogram for the generated data.

## Code:

``````data = randn(100,1);
h = histogram(data)``````

## Output:

Once any histogram object is created, it can be altered by altering its property values, that makes changes in the properties of bins and thus in the display.

## Properties of Histogram in Matlab

Various properties that are featured for the histogram in MATLAB, are as follows:

## 2. Categories

This property allows to plot histogram for each category defined in the input categorical array. If bin count is specified, categories sets the associated category descriptions in the plot.

This property contains parameters such as mentioned below:

## 3. Data

This value gets distributed over a histogram plot among the bins. This property consists of different parameters such as:

## 5. Legend

This property in the MATLAB adds descriptive labels to the plots. It comprises of: