fitting a normal distribution function to a set of data
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Star Strider
2014-12-18
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!