clear;
for n = 1 :40
    if(unifrnd(0,1) > 0.5)
        x(n) = normrnd(2, 0.5);
        y(n) = normrnd(2, 0.5);
        z(n) = normrnd(2, 0.5);
    else
        x(n) = normrnd(5, 0.5);
        y(n) = normrnd(5, 0.5);
        z(n) = normrnd(5, 0.5);
    end;
end

datos = [x', y', z'];
%datos = [x', y'];


[medias, b ] = kmeans(datos, 2)  

dim = length(datos(1, :));
for k=1:length(x)
    switch(b(k))
    case 1 
        if (dim == 2) plot(datos(k,1), datos(k,2), 'kx'), end;
        if (dim == 3) plot3(datos(k,1), datos(k,2), datos(k,3), 'kx'), end; 
    case 2 
        if (dim == 2) plot(datos(k,1), datos(k,2), 'bx'), end;
        if (dim == 3) plot3(datos(k,1), datos(k,2), datos(k,3), 'bx'), end; 
    case 3
        if (dim == 2) plot(datos(k,1), datos(k,2), 'gx'), end;
        if (dim == 3) plot3(datos(k,1), datos(k,2), datos(k,3), 'gx'), end; 

    end;
end;
hold off;    