Fiting for normalized histrogram.

15 views (last 30 days)
Andrew Kim
Andrew Kim on 4 Nov 2020
Edited: Pradeesh on 5 Nov 2020
Hi
I want to make a fit for my histogram that is normalized. The histfit function does not seem to normalize with probability. Can somebody help me fit the histogram written below?
step = 1000; % Shows the number of steps
P = zeros(step,1);
x = [1:10000];
added = 0;
d = 0;
for i=1:10000 %The simulation repeats for 100,000 times
added = 0;
for j=2:step
R = rand;
if R < 0.5
S = -1;
elseif R > 0.5
S = 1;
end
P(j) = S+P(j-1);
end
x(i) = P(length(P));
added = added + x(i);
end
histogram(x,'Normalization','probability');

Answers (2)

Star Strider
Star Strider on 5 Nov 2020
Divide the ‘Bar’ object and the ‘Line’ object by thier maximum values:
figure
hfh = histfit(x);
hfh(1).YData = hfh(1).YData/max(hfh(1).YData);
hfh(2).YData = hfh(2).YData/max(hfh(2).YData);
That should produce the result you want.

Pradeesh
Pradeesh on 5 Nov 2020
Edited: Pradeesh on 5 Nov 2020
You may follow the documentation to use the following function for fitting normalized histogram for which a sample fit for normalized histogram is provided.
fitdist

Categories

Find more on Neuroimaging in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!