
function mas_cercano=clasificador(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,punto,GRAFICO)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%clasificador: distancia euclidea a las medias de cada clase

%mascercano indica cual es la clase mas cercana al punto que se le pasa

%p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12 son los puntos de 2 dimensiones
%correspondientes a las caras

%punto es el punto de 2 dim a clasificar

%GRAFICO = 1, activa los graficos
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  
N=12; %numero de individuos en CARAS0405


%%%%%%%%%%%%%%%%%%%%%%%%%%
% MEDIA DE CADA CLASE
for i=1:N
    comando=sprintf('media_%d=mean(p%d,2);',i,i);
    eval(comando)
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%DISTANCIA DEL PUNTO A CADA MEDIA
for i=1:N
       comando=sprintf('d(%d)=norm(punto-media_%d);',i,i);
       eval(comando);
end
   
[distancia clase]=min(d);
mas_cercano=clase;

if GRAFICO
    
    
figure(1)
c1=1; %%%%%%%% 2 dimensiones
c2=2;
%%%%%%%%%proyecciones
plot(p1(c1,:),p1(c2,:),'b*')
hold on
plot(p2(c1,:),p2(c2,:),'g*')
plot(p3(c1,:),p3(c2,:),'r*')
plot(p4(c1,:),p4(c2,:),'c*')
plot(p5(c1,:),p5(c2,:),'m*')
plot(p6(c1,:),p6(c2,:),'y*')
plot(p7(c1,:),p7(c2,:),'bx')
plot(p8(c1,:),p8(c2,:),'bo')
plot(p9(c1,:),p9(c2,:),'go')
plot(p10(c1,:),p10(c2,:),'ro')
plot(p11(c1,:),p11(c2,:),'co')
plot(p12(c1,:),p12(c2,:),'mo')
grid
legend('cara1','cara2','cara3','cara4','cara5','cara6','cara7','cara8','cara9','cara10','cara11','cara12')

figure(2)
%%%%%%%%%medias
h=plot(media_1(c1,:),media_1(c2,:),'b*');
set(h,'LineWidth',5);
hold on
h=plot(media_2(c1,:),media_2(c2,:),'g*');
set(h,'LineWidth',5);
h=plot(media_3(c1,:),media_5(c2,:),'r*');
set(h,'LineWidth',5);
h=plot(media_4(c1,:),media_4(c2,:),'c*');
set(h,'LineWidth',5);
h=plot(media_5(c1,:),media_5(c2,:),'m*');
set(h,'LineWidth',5);
h=plot(media_6(c1,:),media_6(c2,:),'y*');
set(h,'LineWidth',5);
h=plot(media_7(c1,:),media_7(c2,:),'bx');
set(h,'LineWidth',5);
h=plot(media_8(c1,:),media_8(c2,:),'bo');
set(h,'LineWidth',5);
h=plot(media_9(c1,:),media_9(c2,:),'go');
set(h,'LineWidth',5);
h=plot(media_10(c1,:),media_10(c2,:),'ro');
set(h,'LineWidth',5);
h=plot(media_11(c1,:),media_11(c2,:),'co');
set(h,'LineWidth',5);
h=plot(media_12(c1,:),media_12(c2,:),'mo');
set(h,'LineWidth',5);

%%%%%%% el punto a clasificar
h=plot(punto(c1,:),punto(c2,:),'ks');
set(h,'LineWidth',5);
grid
legend('cara1','cara2','cara3','cara4','cara5','cara6','cara7','cara8','cara9','cara10','cara11','cara12')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(3)%%%todo junto
%%%%%%%%%proyecciones
plot(p1(c1,:),p1(c2,:),'b*')
hold on
plot(p2(c1,:),p2(c2,:),'g*')
plot(p3(c1,:),p3(c2,:),'r*')
plot(p4(c1,:),p4(c2,:),'c*')
plot(p5(c1,:),p5(c2,:),'m*')
plot(p6(c1,:),p6(c2,:),'y*')
plot(p7(c1,:),p7(c2,:),'bx')
plot(p8(c1,:),p8(c2,:),'bo')
plot(p9(c1,:),p9(c2,:),'go')
plot(p10(c1,:),p10(c2,:),'ro')
plot(p11(c1,:),p11(c2,:),'co')
plot(p12(c1,:),p12(c2,:),'mo')
grid
%%%%%%%%%medias
h=plot(media_1(c1,:),media_1(c2,:),'b*');
set(h,'LineWidth',5);
h=plot(media_2(c1,:),media_2(c2,:),'g*');
set(h,'LineWidth',5);
h=plot(media_3(c1,:),media_5(c2,:),'r*');
set(h,'LineWidth',5);
h=plot(media_4(c1,:),media_4(c2,:),'c*');
set(h,'LineWidth',5);
h=plot(media_5(c1,:),media_5(c2,:),'m*');
set(h,'LineWidth',5);
h=plot(media_6(c1,:),media_6(c2,:),'y*');
set(h,'LineWidth',5);
h=plot(media_7(c1,:),media_7(c2,:),'bx');
set(h,'LineWidth',5);
h=plot(media_8(c1,:),media_8(c2,:),'bo');
set(h,'LineWidth',5);
h=plot(media_9(c1,:),media_9(c2,:),'go');
set(h,'LineWidth',5);
h=plot(media_10(c1,:),media_10(c2,:),'ro');
set(h,'LineWidth',5);
h=plot(media_11(c1,:),media_11(c2,:),'co');
set(h,'LineWidth',5);
h=plot(media_12(c1,:),media_12(c2,:),'mo');
set(h,'LineWidth',5);

%%%%%%% el punto a clasificar
h=plot(punto(c1,:),punto(c2,:),'ks');
set(h,'LineWidth',5);




end

