knnsearch
Find k-nearest neighbors.
📝Syntax
idx = knnsearch(X, Y)
idx = knnsearch(X, Y, Name, Value)
[idx, D] = knnsearch(...)
📄Description

knnsearch finds nearest rows of X for each query row of Y using an exhaustive native search.

Supported options include K, Distance, IncludeTies, NSMethod, SortIndices, P, Scale, Cov, BucketSize, and CacheSize. When IncludeTies is true, outputs are cell arrays.

💡Examples
X = [0 0; 1 0; 0 2; 4 4];
Y = [0 1; 3 4];
[idx, D] = knnsearch(X, Y, 'K', 2)
🔗See Also
pdistpdist2
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub