function cluster = kmeans(M, K, cent) doLoop = 1; while(doLoop) W = cent; cluster = zeros(1); for i=1:size(M,1) minval = 1000; for j=1:K temp = norm(M(i,:)-W(j,:)) if(temp < minval) minval = temp; cluster(i) = j; end end end for j=1:K end %Check if we should continue the whileloop end