function centers=k_means(vectors,num_cluster)
    
    rand('state',sum(100*clock));
    
    tempsize=size(vectors);
    num_instance=tempsize(1);
    dimensionality=tempsize(2);
    
    initials(1,1)=ceil(rand*num_instance);
    for i=1:num_cluster-1
        success=0;
        while(success==0)
            pointer=ceil(rand*num_instance);
            if(sum(initials==pointer)==0)
                initials(1,i+1)=pointer;
                success=1;
            end
        end
    end

    
    for i=1:num_cluster
        centers(i,:)=vectors(initials(1,i),:);
    end
    
    num_iter=0; 
    complete=0;
    while(complete==0)
        distance=zeros(num_instance,num_cluster);
        for i=1:num_instance
            for j=1:num_cluster
                distance(i,j)=sum((vectors(i,:)-centers(j,:)).^2);
            end
        end
        
        clusters=cell(num_cluster,1);
        for i=1:num_instance
            [minimum,index]=min(distance(i,:));
            clusters{index,1}=[clusters{index,1},i];
        end
        
        for i=1:num_cluster
            tempsize=size(clusters{i,1});
            if(tempsize(2)==0)
                new_centers(i,:)=centers(i,:);
            else
                temp_center=zeros(1,dimensionality);
                for j=1:tempsize(2)
                    temp_center=temp_center+vectors(clusters{i,1}(1,j),:);
                end
                new_centers(i,:)=temp_center/tempsize(2);
            end
        end
        
        for i=1:num_cluster
            identical=0;
            for j=1:num_cluster
                if(sum(new_centers(i,:)==centers(j,:))==dimensionality)
                    identical=1;
                    break;
                end
            end        
            if(identical==0)              
                break;
            end
        end
        centers=new_centers;
        if(identical==1)
            complete=1;
        end
        
        num_iter=num_iter+1;
    end
            