%% Generate FIS Using FCM Clustering
% Obtain the input and output data.

load clusterdemo.dat
inputData = clusterdemo(:,1:2);
outputData = clusterdemo(:,3);

%
% Create a genfisOptions option set for FCM Clustering, specifying a Mamdani FIS type.

opt = genfisOptions('FCMClustering','FISType','mamdani');

%
% Specify the number of clusters.

opt.NumClusters = 3;

%
% Suppress the display of iteration information to the Command Window.

opt.Verbose = 0;

%
% Generate the FIS.

fis = genfis(inputData,outputData,opt);

%
% The generated FIS contains one rule for each cluster.

showrule(fis)

%
% Plot the input and output membership functions.

[x,mf] = plotmf(fis,'input',1);
subplot(3,1,1)
plot(x,mf)
xlabel('Membership Functions for Input 1')
[x,mf] = plotmf(fis,'input',2);
subplot(3,1,2)
plot(x,mf)
xlabel('Membership Functions for Input 2')
[x,mf] = plotmf(fis,'output',1);
subplot(3,1,3)
plot(x,mf)
xlabel('Membership Functions for Output')

% Copyright 2012 The MathWorks, Inc.