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

採用された回答

Walter Roberson
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
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 件)

Junaid
Junaid 2012 年 2 月 5 日
Kindly reformat your code. Make it readable.

Ming-Gar Lee
Ming-Gar Lee 2012 年 2 月 6 日
[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

カテゴリ

Help Center および File ExchangeFuzzy Logic Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by