目标:查询目标点附近的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,:))