基于KD-Tree的最近邻搜索

2018/11/27 20:01
阅读数 613

目标:查询目标点附近的10个最近邻邻居。

load fisheriris  
x = meas(:,3:4);  
figure(100);
g1=gscatter(x(:,1),x(:,2),species);  %species分类中是有三个分类:setosa,versicolor,virginica
legend('Location','best')  
newpoint = [5 1.45];  
line(newpoint(1),newpoint(2),'marker','x','color','k',...  
   'markersize',10,'linewidth',2)  
Mdl = KDTreeSearcher(x)  ;
[n,d] = knnsearch(Mdl,newpoint,'k',10); %k代表个数,即搜索给定点附近的几个最近邻点 
line(x(n,1),x(n,2),'color',[.5 .5 .5],'marker','o',...  
    'linestyle','none','markersize',10)  
disp(x(n,:))

 

展开阅读全文
mdl
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部