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

2 次查看(过去 30 天)
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 个评论
Ameer Hamza
Ameer Hamza 2020-3-6
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 2020-3-6
Thank you. i really appreciate your help. i guess i was just over complicating the problem

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by