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

    %% Fit a Kernel Distribution to Data  

% Copyright 2015 The MathWorks, Inc.


%% 
% Load the sample data. Create a vector containing the patients' weight data. 
load hospital
x = hospital.Weight;  

%% 
% Create a kernel distribution object by fitting it to the data. Use the
% Epanechnikov kernel function. 
pd = fitdist(x,'Kernel','Kernel','epanechnikov')  

%% 
% Plot the pdf of the distribution. 
x_values = 50:1:250;
y = pdf(pd,x_values);
plot(x_values,y)