k-means algorithm

Runs the k-means algorithm on N random points on a given shape.
1.8K Downloads
Updated 5 Mar 2010

View License

[counter] = kMeans(numPoints, numClusters, shape, drawOn, showOn)
This function takes as inputs: numPoints: the number of random points to cluster; numClusters: the number of clusters to group the points into; shape: a string 'square', 'circle', or 'tube' to carry out the kMeans process in; drawOn: a 1 or 0 indicating whether or not to show the points dynamically joining different clusters (not suitable for more than 500 points) ; showOn: a 1 or 0 indicating whether or not to show the update in clusters as a new figure after each iteration

Given the appropriate parameters kMeans first places k = numClusters random points in the given SHAPE and then carries out the kMeans algorithm. That is, we first assign each of the N = numPoints to the initial mean which is closest (in the standard Euclidean sense), then compute the centroid/center of mass of each cluster and then begin the reassignment process again.

Eventually, the algorithm will stabilize, and plots the final clusters as well as the path that the k means have followed.

Cite As

Tyler London (2024). k-means algorithm (https://www.mathworks.com/matlabcentral/fileexchange/26856-k-means-algorithm), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0