How to plot over histogram function

조회 수: 42 (최근 30일)
Camilo Israel Chavez Galvan
Camilo Israel Chavez Galvan 2020년 11월 10일
댓글: Camilo Israel Chavez Galvan 2020년 11월 10일
I have the following code:
figure(2)
[h] = histogram(norm,100);
hold on
a=h.BinCounts;
b=h.BinEdges;
gaussiana = (1/(sqrt(2*pi)*desviacion))*exp(-0.5*(((b)/(desviacion)).^2));
laplaciana = (1/(sqrt(2)*desviacion))*exp(-(sqrt(2)*abs(b))/(desviacion));
gamma = (sqrt(sqrt(3)./(8.*pi.*desviacion.*abs(b)))).*exp(-(sqrt(3).*abs(b))./(2.*desviacion));
plot(b,gaussiana,'linewidth',2);
hold on
plot(b,laplaciana,'linewidth',2);
hold on
plot(b,gamma,'linewidth',2);
I am trying to plot over histogram but I cant make it work, I know that it is possible to do it using the old 'hist' function and then using 'bar', but I don't want to use that.

채택된 답변

dpb
dpb 2020년 11월 10일
>> figure(2)
[h] = histogram(norm,100);
...
Error using norm
Not enough input arguments.
>>
Your code even if fix the above doesn't normalize the histogram...try something like
hH=histogram(randn([100,1]),'Normalization','pdf');
hold on
x=linspace([-3,3]);
hL=line(x,normpdf(x));
which yielded for one particular trial
  댓글 수: 1
Camilo Israel Chavez Galvan
Camilo Israel Chavez Galvan 2020년 11월 10일
I guess I should have took a look at the histogram funcion properties, thank you so much!, I was able to make it work like I wanted it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by