How can I plot this kind of smoothed probability distribution in Matlab?
If you have the equation to the PDF, you can simply plot it for specified values of x. For example,
Normal distribution
pNormal=@(x)1/sqrt(2*pi)*exp(-(x.^2)/2);
x=linspace(-4,4,1e3);
plot(x,pNormal(x));
Log-Normal distribution
pLogNormal=@(mu,sigma,x)1./(x*sigma*sqrt(2*pi)).*exp(-((log(x)-mu)./(sqrt(2)*sigma)).^2);
x=linspace(0,10,1e3);
mu=0;sigma=1;
plot(x,pLogNormal(mu,sigma,x));
You can vary sigma
, mu
and x
according to your needs. The log-normal distribution is defined for x>0
.
Here is an example that uses a kernel smoother. (Just in case you don't know what distribution describes your data sample)
% generate some random data
X1 = 10 + randn(100,1);
X2 = 15 + 2*randn(75,1);
X3 = 25 + 3*randn(125,1);
X = vertcat(X1,X2,X3);
% use a kernel smoother to model X
foo = fitdist(X,'kernel')
% inspect the methods of foo
methods(foo)
% Plot the pdf of foo
range = linspace(min(X), max(X), 100);
bar = pdf(foo, range)
plot(range, bar)
精彩评论