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


function [FailCount,FailIndex]=OneNear(xnrL,xntL,xnr,xnt,xnrCount,xntCount,CountL,dem) 
 
FailCount=0; FailIndex=zeros(xntCount,1); 
k=1; 
for i=1:xntCount 
    MinIndex=1; 
    if(dem==2)   
        MinOdis=(xnr(1,1)-xnt(i,1))^2+(xnr(1,2)-xnt(i,2))^2; 
    end; 
    if(dem==3)   
        MinOdis=(xnr(1,1)-xnt(i,1))^2+(xnr(1,2)-xnt(i,2))^2+(xnr(1,3)-xnt(i,3))^2; 
    end; 
    for j=1:xnrCount 
        if(dem==2)   
            OdisTemp=(xnr(j,1)-xnt(i,1))^2+(xnr(j,2)-xnt(i,2))^2;    
        end; 
        if(dem==3)  
            OdisTemp=(xnr(j,1)-xnt(i,1))^2+(xnr(j,2)-xnt(i,2))^2+(xnr(j,3)-xnt(i,3))^2;      
        end; 
        if(OdisTemp<MinOdis)  
            MinOdis=OdisTemp;  MinIndex=j;   
        end; 
    end; 
 
    if((CountL==2)&(((MinIndex<=xnrL(1,1))&(i>xntL(1,1)))|((MinIndex>xnrL(1,1))&(i<=xntL(1,1))))) 
        FailCount=FailCount+1;  
        FailIndex(k,1)=i;   
        k=k+1;  
    end; 
 
    if(CountL==3) 
        FailFlag1=0;FailFlag2=0;FailFlag3=0; 
        if((MinIndex<=xnrL(1,1))&(i>xntL(1,1))) 
            FailFlag1=1;  
        end; 
        if((MinIndex>xnrL(2,1))&(i<=xntL(2,1)))  
            FailFlag3=1;     
        end; 
        if(((MinIndex>xnrL(1,1))&(MinIndex<=xnrL(2,1)))&((i>xntL(2,1))|(i<=xntL(1,1)))) 
            FailFlag2=1;  
        end; 
        if(FailFlag1|FailFlag2|FailFlag3)  
            FailCount=FailCount+1;FailIndex(FailCount,1)=i;   
        end; 
    end; 
end;