function [clustercenter Mugrade] = FCM(c,A,Muinitial,m,tolerancence, imaxiteration )% Fuzzy C Mean Algorithm
% A is the data array with nx2, i.e., those are n observations in 2 dimension
% which we first consider
% c is the the number of partitions in the data space.
% Muinitial is the initial grade of memberships with cxn
% m (>=1) is the index of fuzziness
% tolerancence
% imaxiteration
clear all[n,mm] = size(A);[c n] = size(Muinitial);Mu = Muinitial;tol=tolerancence;imax=imaxiteration;%If c ~=cm or n ~= nd
% disp('Error: please check the consistence of the dimension of Muinitial')
% else
for k=1:imax M=Mu.^m; V=sum(M'); DIAGONAL=diag(V); CLUSTERCENTER = DIAGONAL*M*A; B=-1*A'; Munew=(CLUSTERCENTER*B).^(-2/(m-1)); W=sum(Munew'); DIAGONAL2=diag(W) Munorrmal=DIAGONAL2*Munew; tori=sum(sum(Mu-Munormal)) if toli < tol break end if k == imax fprint('Solution was not obtained in %k iteration', imax) break end Mu = Munormal;k=k+1; endclustercenter = CLUSTERCENTERMugrade = Munormal for k=1:n plot(A(k,1),A(k,2)) hold onendfor k=1:c plot(clustercenter(k,1),clustercenter(k,2)) hold onendhold off%end
MATLAB: There have the errors after we type FCM(2,'[1 2;2 3;4 5;2 4;3 3;1 5]’,'[0.1 0.2 0.3 0.4 0.5 0.7;0.9 0.8 0.7 0.6 0.5 0.3]’,2, 0.001,5)
how to solve the error "??? reference to a cleared variable a." when i run the function fcm which i created
Best Answer