How to insert a normal line over my histograms? i tried using histfit

1 view (last 30 days)
sd1 = 1081;
mu1 = 1800;
data1 = mu1+ sd1.*randn(5000,1);
sd2 = 1356;
mu2 = 2551;
data2 = mu2+ sd2.*randn(5000,1);
sd3 = 1262;
mu3 = 2331;
data3 = mu3+ sd3.*randn(5000,1);
%bin specs.
nbins = 100;
bound = 10000;
bins = linspace(-bound,bound,nbins);
fig = figure;
% first histogram
y1 = hist(data1,bins);
% second histogram
y2 = hist(data2,bins);
% Third histogram
y3 =hist(data3,bins);
% overlay histograms
bar(y1.');
hold on;
bar(y2.','r');
hold on;
bar(y3.','y');
legend({'Damage Scenario(i)',' Damage Scenario(ii)',' Damage Scenario(iii)'})
% relabel x-axis range/ticks
xd = findobj('property','XData');
for i=1:3
dat = get(xd(i),'XData');
dat = 2*dat/nbins - bound;
set(xd(i),'XData',data);
h=findobj(gca,'Type','patch');
set(h,'FaceColor','white');
end
  4 Comments
Ameer Hamza
Ameer Hamza on 6 Mar 2020
histfit works. For example
sd1 = 1081;
mu1 = 1800;
data1 = mu1+ sd1.*randn(5000,1);
sd2 = 1356;
mu2 = 2551;
data2 = mu2+ sd2.*randn(5000,1);
sd3 = 1262;
mu3 = 2331;
data3 = mu3+ sd3.*randn(5000,1);
%bin specs.
nbins = 100;
bound = 10000;
bins = linspace(-bound,bound,nbins);
fig = figure;
ax = axes();
hold(ax);
histfit(data1,nbins);
histfit(data2,nbins);
histfit(data3,nbins);
How does it differ from your intended output?
kentridge mantsha
kentridge mantsha on 6 Mar 2020
Edited: kentridge mantsha on 6 Mar 2020
Thank you. i really appreciate your help. i guess i was just over complicating the problem

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!