MATLAB: K-means: see the initial centroids

initial centroidkmeans

Hi everyone,
Is it possible to see the randomly selected initial centroids when using the built-in kmeans function? I want to keep track of the centroids in each iteration.
Thanks.

Best Answer

Yes it is possible.
kmeans allows you to set option parameters via the statset function. In the help page kmeans there some examples on how using stateset.
Set the parameter 'OutputFcn' as shown in this tutorial, for displaying iteration results in iterative solvers: https://it.mathworks.com/help/matlab/math/output-functions.html