Calculate number of bins for histogram

版本 1.1.0.0 (4.2 KB) 作者: Richie Cotton
Automatically calculates the 'best' number of bins for a histogram.
4.1K 次下载
更新时间 2008/10/24

查看许可证

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

引用格式

Richie Cotton (2024). Calculate number of bins for histogram (https://www.mathworks.com/matlabcentral/fileexchange/21033-calculate-number-of-bins-for-histogram), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2008a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.1.0.0

NaN values are now consistently ignored in calcnbins.

1.0.0.0

Bug fix