How to insert a normal line over my histograms? i tried using histfit
조회 수: 1 (최근 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
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?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!