2014-12-27 5 views
0

Welcome! 다음 3 열이 XYZ 동안 좌표,Matlab - 3 차원 좌표계에서 가장 가까운 이웃 찾기

xyz_1 -3,37200000000000 2,80000000000000 5,03400000000000 

xyz_2 -2,21700000000000 1,74500000000000 7,45300000000000 

.... .................. ................ ................ 

xyz_n -1,39300000000000 0,00700000000000000 6,35500000000000 

첫 번째 열의 행렬의 이름 :

는 I는 다음과 같은 구조 N MATLAB 행렬들의 세트를 갖는다. 가장 가까운 이웃을 찾는 효율적인 방법을 찾고 있습니다.

[nearest_neighbor_name_1; distance_between_quoted_element_and_nearest_neigbor_1 

nearest_neighbor_name_2; distance_between_quoted_element_and_nearest_neigbor_2 

nearest_neighbor_name_....; distance_between_quoted_element_and_nearest_neigbor_.... 

nearest_neighbor_name_k; distance_between_quoted_element_and_nearest_neigbor_k] 

나는 불행하게도 knnsearch를 사용하려 : 나는 행렬 이름 및 입력 매개 변수로 잠재적 인 이웃의 K 다음 프로그램은 다음과 같은 형태로 나에게 결과 행렬을주는 가장 가까운 이웃을 찾을 수를주고 싶습니다 효과없이. 도와 줘서 고마워!

+0

코드 세그먼트의 경우 \를 사용하여 질문을 다시 포맷하십시오. 또한 : 당신은 무엇을 의미합니까? * knnsearch를 효과없이 사용하려고했습니다 *. 이 접근법이 불만족 스러웠던 이유는 무엇입니까? – knedlsepp

+0

2 차원 좌표를 검색하는 방법에 대한 설명을 찾았습니다. 불행히도 3 차원 시스템의 경우 'knnseach'를 어떻게 사용하는지 전혀 알지 못합니다. 또한, 'knneseach'에 대한 입력 매개 변수는 단일 행렬 (X와 Y)이 아니라 제 경우와 마찬가지로 다중 배열 집합입니다. – destrudos

+0

통찰력을 위해 [this post] (http://stackoverflow.com/questions/27475978/finding-k-nearest-neighbour-with-matlab/27476929#27476929)를보십시오. 각 행을 점으로, 각 열을 변수로 사용하여 데이터 서식을 지정하십시오. – rayryeng

답변

0

전통적인 방식으로 어떤 방식 으로든 만족스럽지 않습니까? 각 점에서 테스트 점까지의 거리를 계산 한 다음 거리를 정렬하십시오.

%define the "k" entries that you are interested in assessing 
mydata_xyz = [-3.37200000000000 2.80000000000000 5.03400000000000; 
       -2.21700000000000 1.74500000000000 7.45300000000000; 
         <the rest of your data here> 
       -1.39300000000000 0.00700000000000000 6.35500000000000]; 

%define the point about which you are looking for the nearest neighbors 
mypoint_xyz = [ <whatever your xyz coordinate is]; 


%compute the distance from the given point to all of the other test points. 
%Note the use of the transpose (apostrophe) to ensure that it sums in the 
% correct direction 
distance = sqrt(sum(((mydata_xyz - ones(size(mydata_xyz,1),1)*mypoint_xyz).^2)')); 

%sort to get the nearest neighbor followed by the next nearest neighbors 
[sorted_distance, Isort] = sort(distance); 

%print out each one of the points, from closest to farthest 
for I=1:length(Isort) 
    disp(['Point ' num2str(Isort) ... 
      ', dist = ' num2str(distance(Isort(I))) ... 
      ', xyz = ' num2str(mydata_xyz(Isort(I),:))]); 
end