k_means_(d, k, distance)

A k-means algorithm for clustering which automatically produces scatterplot of data as well.

You are now following this Submission

I have developed a k-means algorithm which accepts a maximum of 5 clusters. You can specify distance measure to use, i.e. 'euclidean', 'cosine' etc. and the function will also produce a scatter plot of your clustered data.
Please note:
- This is my first attempt at creating a k-means algorithm (created for university module work)
- It is by no means the fastest k-means algorithm available
- Uses random initialisation for initial centroids
- k_means_(d,k,distance)
- I have only tested it with a few types of data and have had great success, hopefully you won't have any problems
- If you are unfamiliar with this algorithm, please note that it requires a minimum of 2 dimensions for it to work.
- Use only numerical data i.e. ratio, interval. This algorithm is not suitable for categorical or ordinal data types.

Cite As

dangrewal (2026). k_means_(d, k, distance) (https://uk.mathworks.com/matlabcentral/fileexchange/48476-k_means_-d-k-distance), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.1.0.0

Added note in description specifying that a minimum of 2 dimensions are needed
minor code update

1.0.0.0