Finding the closest specified value in an array.

8 Ansichten (letzte 30 Tage)
Robert Wanker
Robert Wanker am 30 Okt. 2020
Beantwortet: Gouri Chennuru am 5 Nov. 2020
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 Kommentar
Sindar
Sindar am 30 Okt. 2020
  • What is the size of points?
  • How do you define distance?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Gouri Chennuru
Gouri Chennuru am 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!

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by