k-means algorithm
[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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |