Closest value of huge data, Avoiding excessive iterations
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
I have the location of red dots (1000 points) and black dots (4000 points). The red dots have values associated with them.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191244/image.png)
What I want is for each black dot, find the one closest red dot and get that associated value. So the result would be a matrix of 4000x4, where 4000 is the number of black dots:
Result=[
1 x y AssociatedRedDotValue1
2 x y AssociatedRedDotValue2
3 x y AssociatedRedDotValue3
.
.
.
4000 x y AssociatedRedDotValue4000
]
If I use nested for loop, that would be 4000000 iterations, and will crash my computer. Is there much efficient way to do this?
Thanks in advance.
댓글 수: 0
채택된 답변
KSSV
2018년 6월 14일
Read about knnsearch. This will give you the required number of nearest points for a given point out of the data. This is very fast and effective.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!