[ndata text alldata] = xlsread('battery2.xlsx','li ion');
[R2,C2]=size(alldata);
Life = ndata(:,72);
A=round(Life);
[valu,idxC, idxV] = unique(A);
n = accumarray(idxV,1);
m= [n idxC] ;
y = [valu n];
binWidth = 1;
binCtrs = 0:binWidth:172;
figure
count= hist(Life,binCtrs);
hist(Life,binCtrs,'k');
counts = hist(Life,binCtrs);
nu = length(Life);
prob = counts / (nu * binWidth);
figure
plot(binCtrs,prob,'ko');hold on
k=2
paramEsts= gmdistribution.fit(Life,k)
xgrids = linspace(0,173,100);
y1 = gaussian1D(xgrids, paramEsts.mu(1), paramEsts.Sigma(1));
y2 = gaussian1D(xgrids, paramEsts.mu(2), paramEsts.Sigma(2));
axis([-10 175 0 0.02]);
C=5;
w= [paramEsts.PComponents(1) paramEsts.PComponents(2)];
x=xgrids;
values=binCtrs;
[mu_est, sigma_est, w_est, counter, difference] = gaussian_mixture_model(values, C, 1.0e-3);
mu_est'
sigma_est'
w_est'
p1_est = w_est(1) * norm_density(x, mu_est(1), sigma_est(1));
p2_est = w_est(2) * norm_density(x, mu_est(2), sigma_est(2));
p3_est = w_est(3) * norm_density(x, mu_est(3), sigma_est(3));
p4_est = w_est(4) * norm_density(x, mu_est(4), sigma_est(4));
p5_est = w_est(5) * norm_density(x, mu_est(5), sigma_est(5));
plot2 = plot(x, p1_est+p2_est+p3_est+p4_est+p5_est, 'r--', 'linewidth', 2);