K-means 聚类算法MATLAB代码

%----------------------main function-----------------------------

%% Clear Memory & Command Window

clc
clear
close all
%% Generate Points
Sigma = [0.5 0.05; 0.05 0.5];
f1    = mvnrnd([0.5 0]  ,Sigma,100);
f2    = mvnrnd([0.5 0.5],Sigma,100);
f3    = mvnrnd([0.5 1]  ,Sigma,100);f4    = mvnrnd([0.5 1.5],Sigma,100);


%% K-means options
feature_vector     = F;                                 % Input
number_of_clusters = 8;                                 % Number of Clusters
Kmeans_iteration   = 40;                                % K-means Iteration
%% Test K-means
[cluster_centers, data]  = km_fun(feature_vector, number_of_clusters, Kmeans_iteration); % K-means clusterig
%% Plot
CV    = '+r+b+c+m+k+yorobocomokoysrsbscsmsksy';       % Color Vector
hold on
for i = 1 : number_of_clusters
    PT = feature_vector(data(:, number_of_clusters+1) == i, :);      

你可能感兴趣的:(K-means 聚类算法MATLAB代码)