필터 지우기
필터 지우기

Histogram

조회 수: 10 (최근 30일)
Mate 2u
Mate 2u 2012년 2월 19일
답변: pavan kumar 2021년 8월 6일
Hi everybody. I have an array.
1) I do a histfit(data) to get a histogram representation of my data with a normal distribution curve on top. I want a 3rd thing on this graph and that is a smooth line representing the data (so I want the curve representing the distribution of my data on top of this to compare with the normal distribution)
Thanks.

채택된 답변

Tom Lane
Tom Lane 2012년 2월 19일
There is a ksdensity function that can produce a kernel-smooth density estimate. The issue is that it produces a density (integrates to 1) and the histogram is not a density (bar heights sum to 1). You could figure out the area of the histogram and re-scale the ksdensity values. Alternatively, here's a way to create the histgram, normal curve, and kernel density separately:
x = [randn(100,1); 4+randn(50,1)];
[hts,ctrs] = hist(x)
bar(ctrs,hts,'hist')
area = sum(hts) * (ctrs(2)-ctrs(1))
xx = linspace(-3,7);
hold on; plot(xx,area*normpdf(xx,mean(x),std(x)),'r-')
f = ksdensity(x,xx);
plot(xx,area*f,'g-')
hold off
  댓글 수: 2
tiago
tiago 2013년 9월 11일
Hi, thanks a lot for the help with the code There is any way to know the r^2 of the normal curve?
Thanks in advance
Tom Lane
Tom Lane 2013년 9월 11일
The normal curve is computed from the raw data, which is one-dimensional rather than the two-dimensional x/y data normally associated with R^2. So while maybe you could make something up related to the bar heights and the density values, I don't think there is a good way to apply R^2 here.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jyoti Verma
Jyoti Verma 2019년 11월 13일
a=[4,5,1,2,2,3,4,2,2,1]
b=[4;5;1;2;2;3;4;2;2;1]
n=length(a);
RangeMax=max(a);
RangeMin=min(a);
sizehist=RangeMax-RangeMin+1;
histogram=zeros(sizehist,1);
for i=1:n
histogram(a(i))=histogram(a(i))+1;
end
bar(histogram);

pavan kumar
pavan kumar 2021년 8월 6일
What is the procedure to find the Histogram coefficients?

Community Treasure Hunt

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

Start Hunting!

Translated by