10 nearest neighbors between points

Hi People,
I could really some help asap. I need to figure out how to modify the code proposed by MattJ (from a previous question) in order to find the 10 nearest points to every other point within a group of points (i.e., 10 nearest neighrbors). The points I speak of are the Fermat center points to the Triplets were found in the previous task. I have found all these "center points" and have their coordinates in the attached file (F_points.mat). Any help you could offer would be greatly appreciated.
Best
Steve

3 Kommentare

Walter Roberson
Walter Roberson am 30 Sep. 2019
attachment seems to be missing?
A link to the previous Question would help.
Steve
Steve am 30 Sep. 2019
Sorry about that. Here you go.
Steve
Steve am 30 Sep. 2019
Bearbeitet: Steve am 30 Sep. 2019
I would also like to plot the 10 closest points for each point with lines connecting them if possible. Thank you.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 30 Sep. 2019

1 Stimme

4 Kommentare

I tried using that but could not get it to work. Is there a better way?
Attached is the intermediate file needed fo the following.
Below is the code (that I acquired from MattJ) that I'm trying to make work for this new task:
close all;
clearvars;
load('F_points.mat');
% fx = F_Points{1}(2,1);
for i = 1 : 953
for j = 1 : i
fy(i) = F_points{i}(1,:);
fx(j) = F_points{j}(2,:);
end
end
FermY = fy';
FermX = fx';
X = [FermX,FermY];
thresh=1000; %distance threshold
[D,K]=pdist2(X,X,'euclidean','Smallest',10); X=X.';
K=unique( sort(K).', 'rows').'; K=K(:);
% assert(numel(unique(K))==numel(K) ,'Points not well-separated enough for threshold' );
Fs=num2cell( reshape( X(:,K), 2,10,[] ) ,[1,2]);
Fs=Fs(:).';
C=cell2mat(cellfun(@(z)mean(z,2),Fs,'uni',0) );
% imshow(IM);
hold on; plot_pts2D(flipud(C)); hold off;
Walter Roberson
Walter Roberson am 30 Sep. 2019
The "better way" is to use knnsearch . Your situation is suitable for using KDTreeSearcher
Steve
Steve am 30 Sep. 2019
I tried it and can't get it to do what I need.
Catalytic
Catalytic am 30 Sep. 2019
We can't see what you tried, and so can't know what to advise further.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 30 Sep. 2019

Kommentiert:

am 30 Sep. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by