Find close points in two matrices of coordinates

조회 수: 2 (최근 30일)
Adam Fitchett
Adam Fitchett 2022년 9월 22일
댓글: Adam Fitchett 2022년 9월 28일
I have two different length matrices of 3D coordinates. I want to find all the unique coordinates in one matrix that are within a certain Euclidean distance of any of the coordinates in the other matrix. What is the most efficient way to do this?

채택된 답변

Torsten
Torsten 2022년 9월 22일
편집: Torsten 2022년 9월 22일
Use "pdist2" to calculate the distances of the sites of the first set to the sites of the second set.
Check which rows of the distance matrix D have an entry <= dmax where dmax is your prescribed maximum distance.
These are the sites of the first set you want to determine.
  댓글 수: 3
Torsten
Torsten 2022년 9월 22일
편집: Torsten 2022년 9월 22일
Works for me.
set1 = [0,1,4;
2 5 8];
set2 = [-1,3,6 ;...
4,2,7 ;...
-2 6 9];
dmax = 3;
distance_set1_set2 = pdist2(set1,set2)
distance_set1_set2 = 2×3
3.0000 5.0990 7.3485 4.1231 3.7417 4.2426
indices = any(distance_set1_set2 <= dmax,2)
indices = 2×1 logical array
1 0
set1(indices==1,:)
ans = 1×3
0 1 4
Adam Fitchett
Adam Fitchett 2022년 9월 28일
This worked thanks, although it turned out to be very memory-hungry for my large matrices
Used 98% of the RAM on a workstation with 256 GB of RAM!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by