title: Finding K-nearest neighbors and its implementation
body: <p>I am working on classifying simple data using KNN with Euclidean distance. I have seen an example on what I would like to do that is done with the MATLAB <code>knnsearch</code> function as shown below:</p>
  
  <pre><code>load fisheriris 
  x = meas(:,3:4);
  gscatter(x(:,1),x(:,2),species)
  newpoint = [5 1.45];
  [n,d] = knnsearch(x,newpoint,'k',10);
  line(x(n,1),x(n,2),'color',[.5 .5 .5],'marker','o','linestyle','none','markersize',10)
  </code></pre>
  
  <p>The above code takes a new point i.e. <code>[5 1.45]</code> and finds the 10 closest values to the new point. Can anyone please show me a MATLAB algorithm with a detailed explanation of what the <code>knnsearch</code> function does? Is there any other way to do this?</p>