Fiting for normalized histrogram.

13 次查看(过去 30 天)
Andrew Kim
Andrew Kim 2020-11-4
编辑: Pradeesh 2020-11-5
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');

回答(2 个)

Star Strider
Star Strider 2020-11-5
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 2020-11-5
编辑:Pradeesh 2020-11-5
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

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by