Graphics |
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
.
x = min(yn):.2:max(yn); subplot(1,2,1) hist(yn,x) title('Normally Distributed Random Numbers','FontSize',16)
The second histogram displays the data distribution resulting from the rand
function and explicitly creates 25 bins along the x-axis.
Note
You can change the aspect ratio of the histogram plots using the mouse
to resize the figure window. However, before creating hardcopy output, set the
figure's PaperPositionMode to auto to produce printed output that matches
the display. set(gcf,'PaperPositionMode','auto')
|
Histograms in Polar Coordinates | Discrete Data Graphs |
© 1994-2005 The MathWorks, Inc.