I have implemented this KNN inner distance equation for the output of the knnsearch function.
knnsearch