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)
조회 수: 1 (최근 30일)
이전 댓글 표시
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;
end
clustercenter = CLUSTERCENTER
Mugrade = Munormal
for k=1:n
plot(A(k,1),A(k,2))
hold on
end
for k=1:c
plot(clustercenter(k,1),clustercenter(k,2))
hold on
end
hold off
%end
댓글 수: 0
채택된 답변
Walter Roberson
2012년 2월 5일
You pass A in as a parameter. You execute "clear all" at the start of your routine, thus clearing all variables. You then try to reference A in the very next line.
Any time you have an urge to use "clear all", you should go and lie down until the urge goes away.
댓글 수: 1
Walter Roberson
2012년 2월 5일
You are going to have problems in getting the desired output if you try to use A and MuInitial as character strings, the way you show in your Title.
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fuzzy Logic Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!