Superimposing Normal Distribution on Histogram
8 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'd like to superimpose a gaussian distribution over a histogram.
I am trying to use the histfit function, but following the histfit(x,n) format, where n is the number of bins, n must be a positive integer. I have (and must maintain) and value of n that is not an integer.
(I have to use a bin width of 0.5stdev of the data set. This results in me having 7.4623 bins.)
How do I overcome this problem?
Thx.
0 件のコメント
回答 (1 件)
Wayne King
2012 年 9 月 22 日
編集済み: Wayne King
2012 年 9 月 22 日
Why do you say that you must have a number of bins that is not an integer? How can you have anything but a positive integer for the number of bins?
You can approximate pretty closely a bin width of 1/2*std(data)
data = randn(1000,1);
binwidth = 1/2*std(x);
numbins = round(range(data)/binwidth);
% now construct a histogram just to check bin width
[~,binctrs] = hist(data,numbins);
% look at bin width
mean(diff(binctrs))
% compare to 1/2*std(data)
1/2*std(data)
You should see there is very little difference between the bin width you want and what you get.
Now you can use that number of bins in histfit()
histfit(data,numbins)
1 件のコメント
Phuong Bui
2013 年 9 月 19 日
It's perfect! However, Could you please explain why you can calculate number of bins by this formula. Many thanks
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!