This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Fuzzy c-means clustering


[centers,U] = fcm(data,Nc)
[centers,U] = fcm(data,Nc,options)
[centers,U,objFunc] = fcm(___)



[centers,U] = fcm(data,Nc) performs fuzzy c-means clustering on the given data and returns Nc cluster centers.


[centers,U] = fcm(data,Nc,options) specifies additional clustering options.


[centers,U,objFunc] = fcm(___) also returns the objective function values at each optimization iteration for all of the previous syntaxes.


collapse all

Load data.

load fcmdata.dat

Find 2 clusters using fuzzy c-means clustering.

[centers,U] = fcm(fcmdata,2);
Iteration count = 1, obj. fcn = 8.970479
Iteration count = 2, obj. fcn = 7.197402
Iteration count = 3, obj. fcn = 6.325579
Iteration count = 4, obj. fcn = 4.586142
Iteration count = 5, obj. fcn = 3.893114
Iteration count = 6, obj. fcn = 3.810804
Iteration count = 7, obj. fcn = 3.799801
Iteration count = 8, obj. fcn = 3.797862
Iteration count = 9, obj. fcn = 3.797508
Iteration count = 10, obj. fcn = 3.797444
Iteration count = 11, obj. fcn = 3.797432
Iteration count = 12, obj. fcn = 3.797430

Classify each data point into the cluster with the largest membership value.

maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2,:) == maxU);

Plot the clustered data and cluster centers.

hold on
hold off

Create a random data set.

data = rand(100,2);

Specify a large fuzzy partition matrix exponent to increase the amount of fuzzy ovrelap between the clusters.

options = [3.0 NaN NaN 0];

Cluster the data.

[centers,U] = fcm(data,2,options);

Load the clustering data.

load clusterdemo.dat

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.

objFun =


The optimization stopped because the objective function improved by less than 0.001 between the final two iterations.

Input Arguments

collapse all

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

Number of clusters to create, specified as an integer greater than 1.

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


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.

For an example of fuzzy overlap adjustment, see Adjust Fuzzy Overlap in Fuzzy C-Means Clustering.


Maximum number of iterations, specified as a positive integer.


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


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

  • true — Display objective function.

  • false — Do not display objective function.


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.

Output Arguments

collapse all

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 Nd 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.

Objective function values for each iteration, returned as a vector.


  • To generate a fuzzy inference system using FCM clustering, use the genfis command. For example, suppose you cluster your data using the following syntax:

    [centers,U] = fcm(data,Nc,options);

    where the first M columns of data correspond to input variables, and the remaining columns correspond to output variables.

    You can generate a fuzzy system using the same training data and FCM clustering configuration. To do so:

    1. Configure clustering options.

      opt = genfisOptions('FCMClustering');
      opt.NumClusters = Nc;
      opt.Exponent = options(1);
      opt.MaxNumIteration = options(2);
      opt.MinImprovement = options(3);
      opt.Verbose = options(4);
    2. Extract the input and output variable data.

      inputData = data(:,1:M);
      outputData = data(:,M+1:end);
    3. Generate the FIS structure.

      fis = genfis(inputData,outputData,opt);

    The fuzzy system, fis, contains one fuzzy rule for each cluster, and each input and output variable has one membership function per cluster. For more information, see genfis and genfisOptions.


Fuzzy c-means (FCM) is a clustering method that allows each data point to belong to multiple clusters with varying degrees of membership.

FCM is based on the minimization of the following objective function



  • D is the number of data points.

  • N is the number of clusters.

  • 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.

  • xi is the ith data point.

  • cj is the center of the jth cluster.

  • μij is the degree of membership of xi in the jth cluster. For a given data point, xi, the sum of the membership values for all clusters is one.

fcm performs the following steps during clustering:

  1. Randomly initialize the cluster membership values, μij.

  2. Calculate the cluster centers:


  3. Update μij according to the following:


  4. Calculate the objective function, Jm.

  5. Repeat steps 2–4 until Jm improves by less than a specified minimum threshold or until after a specified maximum number of iterations.


[1] Bezdec, J.C., Pattern Recognition with Fuzzy Objective Function Algorithms, Plenum Press, New York, 1981.

Introduced before R2006a

Was this topic helpful?