Why doesn't hold work with histogram and plot? How do I plot fit distribution on top of histogram?

조회 수: 9 (최근 30일)
The following code fails to plot the probability function on top of the histogram, producing only the figure below. It appears hold does not work with histogram. How do I use plot and histogram together in the same figure?
x = [-2:.1:2];
figure
subplot(1,3,1)
histogram(InterfractionalMotion.x)
hold
plot(x,normpdf(x,normal.x.mu,normal.x.sigma))
hold off
xlabel('Left, mm')
subplot(1,3,2)
hold
histogram(InterfractionalMotion.y)
plot(x,normpdf(x,normal.y.mu,normal.y.sigma))
hold off
xlabel('Posterior, mm')
subplot(1,3,3)
hold
histogram(InterfractionalMotion.z)
plot(x,normpdf(x,normal.z.mu,normal.z.sigma))
hold off
xlabel('Superior, mm')
When I execute the script, the MATLAB console outputs:
Current plot held
Current plot held
Current plot held
  댓글 수: 1
Daniel Bridges
Daniel Bridges 2018년 3월 8일
I have found that it is working to plot both in the same subplot, but that the histogram must be normalized to 1 for it to be displayed as desired.

댓글을 달려면 로그인하십시오.

답변 (1개)

Daniel Bridges
Daniel Bridges 2018년 3월 8일
The following code results in scaling the probability distribution.
x = [-20:.1:20];
f = figure;
p = uipanel('Parent',f,'BorderType','none');
p.Title = 'Interfractional Motion Per DICOM Axis';
p.TitlePosition = 'centertop';
p.FontSize = 12;
p.FontWeight = 'bold';
subplot(1,3,1,'Parent',p)
histx = histogram(InterfractionalMotion.x);
hold
plot(x,max(histx.Values)*normpdf(x,normal.x.mu,normal.x.sigma),'k')
hold off
xlabel('Left, mm')
subplot(1,3,2,'Parent',p)
hold
histy = histogram(InterfractionalMotion.y);
plot(x,max(histy.Values)*normpdf(x,normal.y.mu,normal.y.sigma),'k')
hold off
xlabel('Posterior, mm')
subplot(1,3,3,'Parent',p)
histz = histogram(InterfractionalMotion.z);
hold
plot(x,max(histz.Values)*normpdf(x,normal.z.mu,normal.z.sigma),'k')
hold off
xlabel('Superior, mm')
... but are these really the best fit normal distributions to this data?

카테고리

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