title: How to define weights for KNN?
body: <p>I want to identify a set of weights for the distance measure in KNN method. I read through the MATLAB help and I found that there are functions for inverse or squared inverse (w.r.t the distances) weights however a user defined weights must be a function of the form: <code>@ fnc</code>
  where</p>
  
  <blockquote>
    <p><code>fcn</code> is a function that accepts a matrix of nonnegative distances, and returns a matrix the same size containing nonnegative distance weights. For example, <code>inversesquared</code> is equivalent to <code>@(d)d.^(-2)</code>.</p>
  </blockquote>
  
  <p>I had defined the function to provide a random set of weights:</p>
  
  <pre><code>function WGT=gene 
  weights=round(rand(a,b))
  WGT=T
  end
  </code></pre>
  
  <p>However, when I apply KNN the weights does not changed and are equally distributed.</p>