nearest neighbour search for scattered data

4 Ansichten (letzte 30 Tage)
AAS
AAS am 30 Sep. 2020
Beantwortet: Ameer Hamza am 30 Sep. 2020
Is there any way to find 10 nearest neighbours for each point in a scattered data set? Basically I would like to do the knn search with a number of points instead of radius.

Antworten (1)

Ameer Hamza
Ameer Hamza am 30 Sep. 2020
One method is to calculate pairwise distances using pdist(), and the using mink() to calculate the ten closest points.
x = rand(100,1); % generate 100 random points
y = rand(100,1);
dists = squareform(pdist([x y]));
dists(dists==0) = inf; % so that the point does not match with itself;
[~, I] = mink(dists, 10, 2); % 100x10 matrix
Matrix I contain 100 rows (equal to the number of points) and ten columns (each entry is the index of the closest point).

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by