- What is the size of points?
- How do you define distance?
Finding the closest specified value in an array.
7 views (last 30 days)
Show older comments
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 Comment
Answers (1)
Gouri Chennuru
on 5 Nov 2020
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 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!