function [idx] = myKmeans(vec, nk)
	ni = length(vec);
	m = vec(randi(ni,nk)); % random K means
	idx = zeros(1,ni);
	idxt = zeros(1,ni);
	
	for ite = 1:1000
		for i=1:ni
			minDist = abs(vec(i)-m(1));
			k = 1;
			for j=2:nk
				dist = abs(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)/nxi;
		end
		if sum(idx-idxt) == 0
			break;            
		end
		idxt = idx;
	end
end