The mistake is in using hist. Plot x vs. y instead, because y is the value of the pdf itself.
x= randn(100,1) * sqrt(16)+10; mu = 10; sigma = 4; pd = makedist('Normal',mu,sigma); y=pdf(pd,x);
figure plot(x,y,'.')
The mistake is in using hist. Plot x vs. y instead, because y is the value of the pdf itself.
x= randn(100,1) * sqrt(16)+10; mu = 10; sigma = 4; pd = makedist('Normal',mu,sigma); y=pdf(pd,x);
figure plot(x,y,'.')
You fell into the same trap of not multiplying by dx. I'm not certain, but you may also failed to account for the fact that your values of y are not ordered. So, I think you may have gotten a more-or-less random answer.
There is no need to choose your x at random. It would be much better to choose an evenly spaced array of x from the beginning, and your whole problem becomes simpler.
Like this ...
mu = 10; sigma = 4;
dx = 0.01;
x = mu - 5*sigma : dx : mu + 5*sigma;
pd = makedist('Normal',mu,sigma); y=pdf(pd,x); figure plot(x,y)
probability_total = sum(dx*y)
Probability_x_greater_than_5 = sum(dx.*y(x>5))
I got 0.8941 for that probability.
Notice that these are probabilities, so they lie between 0 and 1. If you want them represented as percentages, then divide by 0.01.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!