The problem occurs since you use the cluster
method to get initial centroids. From MATLAB documentation:
'cluster' - Perform preliminary clustering phase on random 10% subsample of X. This preliminary phase is itself initialized using 'sample'.
So when j=6
, it tries to divide 10% of data into 6 clusters, i.e. 10% of 54 ~ 5. Therefore, you get the error X must have more rows than the number of clusters
.
To get around this problem, either choose the points randomly (sample
method) or choose points uniformly (uniform
method).