how can I put the histfit function in terms of probability?

조회 수: 86 (최근 30일)
Hi, I am using the histfit function, but I need the y-axis to stay in terms of probability (0-1). how can I do this?

채택된 답변

Star Strider
Star Strider 2020년 9월 16일
That is not directly possible with histfit, however it is not impossible:
data = randn(1,100)+1; % Create Vector
figure
histfit(data) % Original
hh = histfit(data);
figure
ybar = hh(1).YData;
bar(hh(1).XData, ybar/sum(ybar), 'BarWidth',1) % Probability
hold on
plot(hh(2).XData, hh(2).YData/sum(ybar), 'r', 'LineWidth',2)
hold off
.
  댓글 수: 2
Andrés Ardila Ardila
Andrés Ardila Ardila 2020년 9월 16일
OK thank you very much
Star Strider
Star Strider 2020년 9월 16일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (1개)

the cyclist
the cyclist 2020년 9월 16일
Here's one way:
% Made-up data
data = randn(500,1);
% Fit to a normal (or a different distribution if you choose)
pd = fitdist(data,'normal');
% Find the pdf that spans the disribution
x_pdf = linspace(min(data),max(data));
y_pdf = pdf(pd,x_pdf);
% Plot
figure
hold
histogram(data,'Normalization','pdf')
line(x_pdf,y_pdf,'LineWidth',2)

Community Treasure Hunt

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

Start Hunting!

Translated by