Page 95 - Algorithm Collections for Digital Signal Processing Applications using MATLAB
P. 95
2. Probability and Random Process 83
4.3 Matlab Program for the Fuzzy k-means Algorithm
Applied for the Example given in the Section 4-2
___________________________________________________________
fuzzykmeansgv.m
%Fuzzy k-means algorithm
a=rand(1,100);
s=[];
fm=[];
for i=1:1:100
r=rand(1,6);
r=r/sum(r);
fm=[fm;r];
end
%Computation of centroids using fuzzy membership
for l=1:1:10
for i=1:1:6
cen{i}=sum((fm(:,i).^2).*a')/sum(fm(:,i).^2);
end
%Updating fuzzy membership value (fm)
fm1=[];
for p=1:1:6
for q=1:1:100
temp=0;
for r=1:1:6
temp =temp+(((a(q)-cen{p})^2)/((a(q)-(cen{r}))^2))^2;
end
fm1(q,p)=1/temp;
end
end
s=[s sum(sum((fm-fm1).^2))];
fm=fm1;
b=cell2mat(cen);
M=[(a-b(1)).^2;(a-b(2)).^2;(a-b(3)).^2;(a-b(4)).^2;(a-b(5)).^2;(a-b(6)).^2;];
[P,CLUSTERNO]=min(M);
u=['r','g','b','c','m','y'];
figure
for i=1:1:6
[x,y]=find(CLUSTERNO==i);
col=[];