plot(fcmdata(index1,1),fcmdata(index1,2),'ob')
hold on
plot(fcmdata(index2,1),fcmdata(index2,2),'or')
plot(centers(1,1),centers(1,2),'xb','MarkerSize',15,'LineWidth',3)
plot(centers(2,1),centers(2,2),'xr','MarkerSize',15,'LineWidth',3)
hold off

Set the clustering termination conditions such that the optimization stops when either of the following occurs:

The number of iterations reaches a maximum of 25.

The objective function improves by less than 0.001 between two consecutive iterations.

options = [NaN 25 0.001 0];

The first option is NaN, which sets the fuzzy partition matrix exponent to its default value of 2. Setting the fourth option to 0 suppresses the objective function display.

Cluster the data.

[centers,U,objFun] = fcm(clusterdemo,3,options);

View the objective function vector to determine which termination condition stopped the clustering.

Data set to be clustered, specified as a matrix with N_{d} rows,
where N_{d} is the number of
data points. The number of columns in data is
equal to the data dimensionality.

Clustering options, specified as a vector with the following
elements:

Option

Description

Default

options(1)

Exponent for the fuzzy partition matrix U,
specified as a scalar greater than 1.0. This option
controls the amount of fuzzy overlap between clusters, with larger
values indicating a greater degree of overlap.

If your
data set is wide with a lot of overlap between potential clusters,
then the calculated cluster centers might be very close to each other.
In this case, each data point has approximately the same degree of
membership in all clusters. To improve your clustering results, decrease
this value, which limits the amount of fuzzy overlap during clustering.

Maximum number of iterations, specified as a positive
integer.

100

options(3)

Minimum improvement in objective function between two
consecutive iterations, specified as a positive scalar.

1e-5

options(4)

Information display toggle indicating whether to display
the objective function value after each iteration, specified as one
of the following:

0 — Do not display objective
function.

1 — Display objective function.

1

If any element of options is NaN,
the default value for that option is used.

The clustering process stops when the maximum number of iterations
is reached or when the objective function improvement between two
consecutive iterations is less than the specified minimum.

Final cluster centers, returned as a matrix with Nc rows
containing the coordinates of each cluster center. The number of columns
in centers is equal to the dimensionality of
the data being clustered.

Fuzzy partition matrix, returned as a matrix with Nc rows
and N_{d} columns. Element U(i,j) indicates
the degree of membership of the jth data point
in the ith cluster. For a given data point, the
sum of the membership values for all clusters is one.

m is fuzzy partition matrix exponent
for controlling the degree of fuzzy overlap, with m >
1. Fuzzy overlap refers to how fuzzy the boundaries
between clusters are, that is the number of data points that have
significant membership in more than one cluster.

x_{i} is the ith
data point.

c_{j} is the
center of the jth cluster.

μ_{ij} is
the degree of membership of x_{i} in
the jth cluster. For a given data point, x_{i},
the sum of the membership values for all clusters is one.

fcm performs the following steps during
clustering:

Randomly initialize the cluster membership values, μ_{ij}.