FUNCTION REFERENCE

kmeans

Partition observations around iteratively updated centers.

Partition observations around iteratively updated centers.

Syntax

[idx,C,sumd,D] = kmeans(X,k,'Start',start)

Distance is 'sqeuclidean' (default), 'cityblock' (coordinate medians), 'cosine', or 'correlation'. Spherical distances normalize observations first; correlation also centers each row. Start is 'plus' (default), 'sample', 'uniform', or a finite k-by-p matrix. Replicates defaults to 1, MaxIter to 100, EmptyAction to 'singleton' ('error' and 'drop' also accepted). OnlinePhase='on' adds sequential improving moves; default 'off'. Display is 'off', 'final', or 'iter'. The replicate with least total sumd wins. NaN rows have NaN indices and distances. Dropped clusters retain NaN centers and sums. rng seeds all random starts reproducibly.

Example

[i,c] = kmeans([0;1;9;10],2,'Start',[0;10]);   % i = [1;1;2;2], c = [0.5;9.5]

Differences from MATLAB: N-D start arrays are not supported yet; a matrix start requires one replicate. Iteration-limit warnings use MatRust wording. Random draws share rand's stream but do not match other programs' initialization streams.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.