www.pudn.com > Patternrecognition.rar > MulNear.m, change:2009-04-19,size:2589b


function [MFailCount,MFailIndex]=MulNear(K,xnrL,xntL,xnr,xnt,xnrCount,xntCount,dem,CountL) 
MFailCount=0;MFailIndex=zeros(xntCount,1);qm=1; 
for i=1:xntCount 
    MMIndex=zeros(K,1); CMOdis=zeros(xnrCount,1); CMaxOdis=CMOdis(1,1); 
   for j=1:xnrCount 
       if(dem==2)  
           CMOdis(j,1)=(xnr(j,1)-xnt(i,1))^2+(xnr(j,2)-xnt(i,2))^2;                       
       end; 
       if(dem==3) 
           CMOdis(j,1)=(xnr(j,1)-xnt(i,1))^2+(xnr(j,2)-xnt(i,2))^2+(xnr(j,3)-xnt(i,3))^2; 
       end; 
       if(CMOdis(j,1)>=CMaxOdis)  
           CMaxOdis=CMOdis(j,1);                                        
       end; 
   end; 
 
   if(CountL==2) 
       CtC=0; 
        
       for k=1:K 
           MMOdisTemp=CMOdis(1,1); MMIndexTemp=0; 
           for j=1:xnrCount 
               if(CMOdis(j,1)<=MMOdisTemp) 
                   MMOdisTemp=CMOdis(j,1); 
                   MMIndexTemp=j; 
               end; 
           end; 
           CMOdis(MMIndexTemp,1)=CMaxOdis; MMIndex(k,1)=MMIndexTemp; 
           if(MMIndexTemp>xnrL) 
               CtC=CtC+1; 
           end; 
       end; 
     
       if((CtC>(K-CtC)&(i<=xntL))|(CtC<(K-CtC)&(i>xntL))) 
            MFailCount=MFailCount+1; 
            MFailIndex(qm,1)=i; 
            qm=qm+1; 
        end; 
    end; 
 
    if(CountL==3) 
        CtC1=0;CtC2=0;CtC3=0;  
        FailFlag1=0;FailFlag2=0;FailFlag3=0; 
         
        for k=1:K 
            MMOdisTemp=CMOdis(1,1); 
            MMIndexTemp=0; 
            for j=1:xnrCount 
                if(CMOdis(j,1)<=MMOdisTemp)  
                    MMOdisTemp=CMOdis(j,1); 
                    MMIndexTemp=j; 
                end; 
            end; 
            CMOdis(MMIndexTemp,1)=CMaxOdis;MMIndex(k,1)=MMIndexTemp; 
            if(MMIndexTemp<=xnrL(1,1))                          CtC1=CtC1+1;end; 
            if(MMIndexTemp>xnrL(2,1))                           CtC3=CtC3+1;end; 
            if((MMIndexTemp<=xnrL(2,1))&(MMIndexTemp>xnrL(1,1)))CtC2=CtC2+1;end; 
        end; 
         
        CtCMIndex=1;CtCM=CtC1; 
         
        if(CtC2>=CtCM)                                CtCM=CtC2;CtCMIndex=2;end; 
        if(CtC3>=CtCM)                                CtCM=CtC3;CtCMIndex=3;end; 
        if((CtCMIndex==1)&(i>xntL(1,1)))                        FailFlag1=1;end; 
        if((CtCMIndex==3)&(i<=xntL(2,1)))                       FailFlag3=1;end; 
        if((CtCMIndex==2)&((i>xntL(2,1))|(i<=xntL(1,1))))       FailFlag2=1;end; 
         
        if(FailFlag1|FailFlag2|FailFlag3) 
            MFailCount=MFailCount+1;MFailIndex(MFailC,1)=i;end; 
    end; 
end;