Say I have a plot in Matlab:
x=-10:0.1:10;
plot(normpdf(x, 0, 3));
I would like to fill the area under the curve from -4 < x < 4
. Similar question: If I for example wanted to fill the area to left of the curve from 0.04 < y < 0.1
?
Say I have a plot in Matlab:
x=-10:0.1:10;
plot(normpdf(x, 0, 3));
I would like to fill the area under the curve from -4 < x < 4
. Similar question: If I for example wanted to fill the area to left of the curve from 0.04 < y < 0.1
?
Aabaz' answer is great for the general case, but if you specifically need to color the area under a normal pdf curve, there's actually a function in Statistics Toolbox that does precisely this: normspec.
p = normspec([1-3/128,Inf],1,2/128,'outside')
p =
0.0668
Check the matlab function area
which can help you solve your particular problem.
For example, filling the area under normpdf for -4 < x < 4
x=(-10:0.1:10);
xs=x(x>-4 & x<4);
figure;
hold on;
area(xs,normpdf(xs,0,3));
plot(x,normpdf(x,0,3));
For your second example however I do not know if this will work, but maybe a workaround is possible.
UPDATE: regarding your second question, I think you can achieve this with the Matlab function fill
. I did not test it but I am pretty sure it would work, if you are having difficulties implementing it do not hesitate to ask for help.