How do I fit a PDF to a histogram?
조회 수: 15 (최근 30일)
이전 댓글 표시
I have a histogram that I need to fit a PDF to. The issue is that I only have the frequency information, I don't have the data the histogram was generated from. This is because it was generated pixel by pixel from a large image and then thresholded with an algorithm. I want to find the equation for the PDF that fits the histogram the best. All of the resources I've found online seem to require the actual data set as well, and not just the frequency information. Does anyone know if this is possible? I also have an empirical PDF generated by normalizing the histogram frequencies. Is there a way I could fit a Gaussian equation to that? Thanks.
댓글 수: 0
답변 (1개)
Are Mjaavatten
2017년 10월 24일
If you have access to the curve fitting toolbox (I don't) you can probably use fit. If not, the following example illustrates how to make a fair approximation:
y = randn(10000,1)+7;
x = 3:0.1:11;
binsize = diff(x(1:2));
n = hist(y,x);
f = n/sum(n)/binsize; % probalility per unit length
f = max(f,100*eps); % Force cf to be monotonic
cf = cumsum(f)*binsize; % Cumulative distribution function
mu = interp1(cf,x,0.5);
sigma = diff(interp1(cf,x,...
[0.5*(1+erf(-1/sqrt(2))),0.5*(1+erf(1/sqrt(2)))]))/2;
plot(x,f,x,exp(-(x-mu).^2/2/sigma^2)/sigma/sqrt(2*pi));
댓글 수: 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!