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

2 visualizaciones (últimos 30 días)
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 comentarios
Ameer Hamza
Ameer Hamza el 6 de Mzo. de 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 el 6 de Mzo. de 2020
Editada: kentridge mantsha el 6 de Mzo. de 2020
Thank you. i really appreciate your help. i guess i was just over complicating the problem

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by