fitting a normal distribution function to a set of data

12 ビュー (過去 30 日間)
cgo
cgo 2014 年 12 月 18 日
回答済み: Star Strider 2014 年 12 月 18 日
Hi, I have a set of data, in the form of a histogram (with actual data also ready) and I want to fit a normal distribution curve on it. Is their an efficient way to do it?
Thanks

採用された回答

Star Strider
Star Strider 2014 年 12 月 18 日
If you have the Statistics Toolbox, use the histfit function.
Otherwise, this works:
d = 2*randn(250,1)+20; % Created Data
binrs = min(d):(max(d)-min(d))/25:max(d); % Bin Definitions
knt = histc(d, binrs); % Histogram Counts
s = std(d); % Intial Parameter Estimate
m = mean(d); % Intial Parameter Estimate
% b(1) = mean, b(2) = std, b(3) = amplitude
pdfnrm = @(x,b) b(3) * 1./(b(2)*sqrt(2*pi)) .* exp(-((x-b(1)).^2./(2*b(2).^2)));
SSECF = @(b) sum((knt-pdfnrm(binrs,b)').^2); % Sum-Squared-Error Cost Function
[B,SSE] = fminsearch(SSECF, [m; s; 10]);
figure(1)
bar(binrs,knt,'g') % Plot Histogram
hold on
plot(binrs,pdfnrm(binrs,B),'r') % Plot Normal Distribution
hold off
grid

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by