# hist (Histogram)

Posted 2011.10.26 22:03
주어진 데이터가 어떻게 분포하는지 알기 위한 히스토그램

# hist-Histogram plot

## Alternatives

To graph selected variables, use the Plot Selector  in the Workspace Browser, or use the Figure Palette Plot Catalog. Manipulate graphs in plot edit mode with the Property Editor. For details, see Plotting Tools — Interactive Plotting in the MATLAB Graphics documentation and Creating Graphics from the Workspace Browser in the MATLAB Desktop Tools documentation.

## Syntax

n = hist(Y)
n = hist(Y,x)
n = hist(Y,nbins)
[n,xout] = hist(...)
hist(...)
hist(axes_handle,...)

## Description

A histogram shows the distribution of data values.

n = hist(Y) bins the elements in vector Y into 10 equally spaced containers and returns the number of elements in each container as a row vector. If Y is an m-by-p matrix, hist treats the columns of Y as vectors and returns a 10-by-p matrix n. Each column ofn contains the results for the corresponding column of Y. No elements of Y can be complex or of type integer.

n = hist(Y,x) where x is a vector, returns the distribution of Y among length(x) bins with centers specified by x. For example, ifx is a 5-element vector, hist distributes the elements of Y into five bins centered on the x-axis at the elements in x, none of which can be complex. Note: use histc if it is more natural to specify bin edges instead of centers.

n = hist(Y,nbins) where nbins is a scalar, uses nbins number of bins.

[n,xout] = hist(...) returns vectors n and xout containing the frequency counts and the bin locations. You can usebar(xout,n) to plot the histogram.

hist(...) without output arguments produces a histogram plot of the output described above. hist distributes the bins along thex-axis between the minimum and maximum values of Y.

hist(axes_handle,...) plots into the axes with handle axes_handle instead of the current axes (gca).

## Tips

All elements in vector Y or in one column of matrix Y are grouped according to their numeric range. Each group is shown as one bin. If Y is a matrix, hist scales the current colormap and uses each column number (1:n) to assign each a unique color.

The histogram's x-axis reflects the range of values in Y. The histogram's y-axis shows the number of elements that fall within the groups; therefore, the y-axis ranges from 0 to the greatest number of elements deposited in any bin. The x-range of the leftmost and rightmost bins extends to include the entire data range in the case when the user-specified range does not cover the data range; this often results in "boxes" at either or both edges of the distribution. If you want a plot in which this does not happen (that is, all bins have equal width), you can create a histogram-like display using the bar command.

Histograms bins are created as patch objects and always plotted with a face color that maps to the first color in the current colormap (by default, blue) and with black edges. To change colors or other patch properties, use code similar to that given in the example.

The hist function accepts data that contains inf values, but does not consider them while populating the bins because the bin centers are all finite values. So, you should filter non-finite values before passing them to hist.

## Examples

Generate a bell-curve histogram from Gaussian data.

x = -4:0.1:4;
y = randn(10000,1);
hist(y,x) 

Change the color of the graph so that the bins are red and the edges of the bins are white.

h = findobj(gca,'Type','patch');
set(h,'FaceColor','r','EdgeColor','w')

#### 'Enginius > Matlab' 카테고리의 다른 글

 eig (Eigenvalue and Eigenvector)  (0) 2011.10.27 2011.10.26 2011.10.26 2011.10.25 2011.10.25 2011.10.25
« PREV : 1 : ··· : 429 : 430 : 431 : 432 : 433 : 434 : 435 : 436 : 437 : ··· : 604 : NEXT »