How do I superimpose a pdf over a histogram?
Show older comments
i want to superimpose the pdf to the histogram. i have written those codes. this is the actual question.
Create 10,000 uniform (0, 1) random variables. · Create 10.000 exponentially distributed random variables by applying the inverse function of F (x) X to the above uniform random variables. · Plot the histogram of the exponentially distributed random variables to approximate the actual pdf. · Superimpose the actual pdf to the above histogram.
this is my codes
[u=rand(1,10000);
lam=0.5;
x=-1/lam.*log(1-u);
y=linspace(min(x),max(x));
h=exp(-y/2);
hist(x),
hold on
plot(y,h)
Answers (2)
Sean de Wolski
on 5 Jul 2011
It's plotting both of them; it's just the pdf is on the range of 0-1 (y values) and the histogram is on the range of 0-7000. Normalize by the number of elements to get the histogram on the range of 0-1. Or use subplots and explain the merits of them v. superimposing to your professor.
axis([0 25 0 1])
and you'll see the pdf line.
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!