Finding Neighboring Vectors
Given the distance matrix, DistanceMatrix from ClassDistance.m, find for each row (person), the other column (person) whose pairwise distance is the least.
Contents
Get the size of the distance matrix
[p,q] = size(DistanceMatrix);
For each person, find the closest other person
for row = 1:p % Make a vector out of each row vector of the distance matrix V = DistanceMatrix(row,:); % Find the minimum non-zero value MinDist = min(V(V>0)); % Find where this value occurred NearestNeighbor(2,row) = find(V==MinDist); % Display who is closest to whom disp(['Person ',num2str(row),' is closest to Person ',num2str(NearestNeighbor(2,row))]); % Plot all the pictures in a grid for evaluation of the algorithm subplot(5,ceil(p/5),row) hold on; title(['Person ',num2str(row)]); imshow(reshape(uint8(PicVex(:,row)),r,c,3)) end
Person 1 is closest to Person 2 Person 2 is closest to Person 1 Person 3 is closest to Person 1 Person 4 is closest to Person 1 Person 5 is closest to Person 10 Person 6 is closest to Person 7 Person 7 is closest to Person 6 Person 8 is closest to Person 7 Person 9 is closest to Person 11 Person 10 is closest to Person 5 Person 11 is closest to Person 6