MATLAB Answers

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

37 views (last 30 days)
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?

Accepted Answer

Star Strider
Star Strider on 16 Sep 2020
That is not directly possible with histfit, however it is not impossible:
data = randn(1,100)+1; % Create Vector
histfit(data) % Original
hh = histfit(data);
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

More Answers (1)

the cyclist
the cyclist on 16 Sep 2020
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

Community Treasure Hunt

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

Start Hunting!

Translated by