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)

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

 채택된 답변

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

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개)

[clustercenter Mugrade] = FCMnew(c,A,Muinitial,m,tolerancence, imaxiteration )
% Fuzzy C Mean Algorithm
% Input variables
% 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
% Output variables
% clustercenter is the center of cluster about the given data
% array A
% Mugrade is the fuzzy grade about the the given data array A
[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;
M1=M';
V=sum(M1);
DIAGONAL1=diag(V);
CLUSTERCENTER = (DIAGONAL1\M)*A;
B=-1*A';
Munew=(CLUSTERCENTER*B).^(-2/(m-1));
W=sum(Munew');
DIAGONAL2=diag(W);
Munormal=DIAGONAL2\Munew;
tori=sum(sum(Mu-Munormal));
if tori < 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
x=A(:,1);
y=A(:,2);
plot(x,y,'or','MarkerSize',12)
hold on
xc=clustercenter(:,1);
yc=clustercenter(:,2);
plot(xc,yc,'+b','MarkerSize',15)
hold off

카테고리

도움말 센터File Exchange에서 Data Clustering에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by