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

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

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 9월 30일

1 개 추천

댓글 수: 4

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 2019년 9월 30일
The "better way" is to use knnsearch . Your situation is suitable for using KDTreeSearcher
Steve
Steve 2019년 9월 30일
I tried it and can't get it to do what I need.
Catalytic
Catalytic 2019년 9월 30일
We can't see what you tried, and so can't know what to advise further.

댓글을 달려면 로그인하십시오.

질문:

2019년 9월 30일

댓글:

2019년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by