Calculate number of bins for histogram
by Richie Cotton
11 Aug 2008
(Updated 24 Oct 2008)
Automatically calculates the 'best' number of bins for a histogram.
|
Watch this File
|
| File Information |
| Description |
Two files are included:
CALCNBINS, which calculates the "ideal" number of bins to use in a histogram, using three possible methods. (Freedman-Diaconis', Scott's and Sturges' methods.)
HISTX is a wrapper for Matlab's own histogram function HIST, that uses CALCNBINS to choose the number of bins if none is provided.
Examples:
y = randn(10000,1);
nb = calcnbins(y, 'all')
% nb =
% fd: 57
% scott: 44
% sturges: 15
calcnbins(y) %Uses the middle value from the above
% ans =
% 44
calcnbins(y, 'fd') % Choose your method
% ans =
% 57
histx(y) %Plots a histogram using middle method
histx(y, 'all') %Plots 3 histograms, using each method |
| MATLAB release |
MATLAB 7.6 (R2008a)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Comments and Ratings (4) |
| 18 Aug 2008 |
Richie Cotton
|
|
|
| 13 Aug 2008 |
John D'Errico
|
|
|
| 12 Aug 2008 |
Richie Cotton
|
|
|
| 11 Aug 2008 |
John D'Errico
|
|
|
| Updates |
| 12 Aug 2008 |
Bug fix; dependency on stats toolbox removed. |
| 18 Aug 2008 |
New function; documentation updates. |
| 22 Aug 2008 |
Bug fix |
| 24 Oct 2008 |
NaN values are now consistently ignored in calcnbins. |
|
Contact us