Graphics Previous page   Next Page

Specifying Number of Bins

hist and rose interpret their second argument in one of two ways -- as the locations on the axis or the number of bins. When the second argument is a vector x, it specifies the locations on the axis and distributes the elements in length(x) bins. When the second argument is a scalar x, hist and rose distribute the elements in x bins.

For example, compare the distribution of data created by two MATLAB functions that generate random numbers. The randn function generates normally distributed random numbers, whereas the rand function generates uniformly distributed random numbers.

The first histogram displays the data distribution resulting from the randn function. The locations on the x-axis and number of bins depend on the vector x.

The second histogram displays the data distribution resulting from the rand function and explicitly creates 25 bins along the x-axis.


Previous page  Histograms in Polar Coordinates Discrete Data Graphs Next page

© 1994-2005 The MathWorks, Inc.