
%% 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.


%% Get the size of the distance matrix
	[p,q] = size(DistanceMatrix);
	
%% For each person, find the closest other person	
close all
for row = 1:p
		% Make a vector out of each row vector of the distance matrix
		%V = DistanceMatrix(row,:);
        V = AngleMatrix(row,:);
       
		% Find the minimum non-zero value
		MinDist = min(V(V>0.1));
		% 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)]);
		

		WhoIsSimilarToWhom(row,NearestNeighbor(2,row),PicVex,r,c)
		drawnow;
		pause
end

MrOrMrs_Mode = mode(NearestNeighbor(2,:))
figure; hold on;
xlabel(['MrOrMrs Mode is Person ',num2str(MrOrMrs_Mode),],'FontSize',15);
imshow(reshape(uint8(PicVex(:,MrOrMrs_Mode)),r,c,3))

