Why doesn't hold work with histogram and plot? How do I plot fit distribution on top of histogram?
Show older comments
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 Comment
Daniel Bridges
on 8 Mar 2018
Answers (1)
Daniel Bridges
on 8 Mar 2018
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!