function [idx] = myKmeansColor(vec, nk)
	[mi,ni] = size(vec);
	m = vec(randi(mi,nk,ni)); % random K means
	idx = zeros(mi,1);
	idxt = zeros(mi,1);	
	
	for ite = 1:1000
		for i=1:mi
			minDist = norm(vec(i,:)-m(1,:));
			k = 1;
			for j=2:nk
				dist = norm(vec(i,:)-m(j,:)); % Distance
				if dist < minDist
					minDist = dist;
					k = j;
				end 
			end
		idx(i) = k;
		end		
		for j=1:nk
			xi = vec(idx == j,:);
			nxi = length(xi);
			m(j,:) = sum(xi,1)/nxi;
		end		
		if sum(idx-idxt) == 0
			break;            
		end		
		idxt = idx;
	end
end
