- What is the size of points?
- How do you define distance?
Finding the closest specified value in an array.
1 次查看(过去 30 天)
显示 更早的评论
I have an array called 'Points'. In this array every value is either a 0 or a 1. My code is starting at (1,1) and checking to see if that point is a 0. If it is I want to output that location (1,1), change that original point to a 1 and search for the next closest 0. In this way, I will have a path that finds all of the 0's and will end when it cannot find anymore 0's because they have all been changed to 1's.
My issue is figuring out how to find the next closest 0 to the location I just checked. I have tried using 'knnsearch' but I'm not entirely sure how it works. Here is what I have so far.
u=1;
uu=1;
while AmountZeroes>0
if Points(u,uu)==0
xout=u;
yout=uu;
Points(u,uu)=1;
[u,uu]=% Location of next closest 0
else
%Find next closest 0 and set (u,uu)= Location of 0
xout=u;
yout=uu;
Points(u,uu)=1;
[u,uu]=%Location of next closest 0
end
AmountZeroes=AmountZeroes-1;
end
回答(1 个)
Gouri Chennuru
2020-11-5
Hi Robert,
As per my understanding, you can make use of the Breadth First Search “bfsearch” function available in MATLAB to proceed the function, where each node is a point. In order to search for a particular node you can sort the distance of the points .
Hope this Helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Big Data Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!