Classify points according to euclidean distance
I have a matrix A consisting of 200 vectors of size d.

I want that a matrix B consisting of 4096 vectors gets classified to these points according to the nearest distance rule.

Thus the result should have rows of size B having the id number ( from 1 to 200 ) to which it belongs.

I have written this code via `2 for` loops and it takes lots of time for calculation.

    for i = 1:4096
            counter = 1;
            vector1 = FaceImage(:,i)';
            vector2 = Centroids(1,:);
            distance = pdist( [ vector1 ; vector2] , 'euclidean' );
            for j = 2:200
                  vector2 = Centroids(j,:);
                  temp = pdist( [ vector1 ; vector2] , 'euclidean' );
                  if temp < distance
                        distance = temp;
                        counter = j;
                  end
            end
            Histogram( i ) = counter;
    end

Can somebody help me out increasing the efficiency of the above code ... or perhaps suggest me an inbuilt function ?

Thanks
Classify points according to euclidean distance
===

I have a matrix A consisting of 200 vectors of size d.

I want that a matrix B consisting of 4096 vectors gets classified to these points according to the nearest distance rule.

Thus the result should have rows of size B having the id number ( from 1 to 200 ) to which it belongs.

I have written this code via `2 for` loops and it takes lots of time for calculation.

    for i = 1:4096
            counter = 1;
            vector1 = FaceImage(:,i)';
            vector2 = Centroids(1,:);
            distance = pdist( [ vector1 ; vector2] , 'euclidean' );
            for j = 2:200
                  vector2 = Centroids(j,:);
                  temp = pdist( [ vector1 ; vector2] , 'euclidean' );
                  if temp < distance
                        distance = temp;
                        counter = j;
                  end
            end
            Histogram( i ) = counter;
    end

Can somebody help me out increasing the efficiency of the above code ... or perhaps suggest me an inbuilt function ?

Thanks