www.gusucode.com > stats 源码程序 matlab案例代码 > stats/PDFOfHalfNormalProbabilityDistributionExample.m

    %% PDF of Half-Normal Probability Distribution
% This example shows how changing the values of the |mu| and |sigma|
% parameters alters the shape of the pdf.

%%
% Create four probability distribution objects with different parameters.
pd1 = makedist('HalfNormal');
pd2 = makedist('HalfNormal','mu',0,'sigma',2);
pd3 = makedist('HalfNormal','mu',0,'sigma',3);
pd4 = makedist('HalfNormal','mu',0,'sigma',5);

%%
% Compute the probability density functions (pdfs) of each distribution.
x = 0:0.1:10;
pdf1 = pdf(pd1,x);
pdf2 = pdf(pd2,x);
pdf3 = pdf(pd3,x);
pdf4 = pdf(pd4,x);

%%
% Plot the pdfs on the same figure.
figure;
plot(x,pdf1,'r','LineWidth',2)
hold on;
plot(x,pdf2,'k:','LineWidth',2);
plot(x,pdf3,'b-.','LineWidth',2);
plot(x,pdf4,'g--','LineWidth',2);
legend({'mu = 0, sigma = 1','mu = 0, sigma = 2',...
    'mu = 0, sigma = 3','mu = 0, sigma = 5'},'Location','NE');
hold off;

%%
% As |sigma| increases, the curve flattens and the peak value becomes
% smaller.