필터 지우기
필터 지우기

Finding the closest specified value in an array.

조회 수: 7 (최근 30일)
Robert Wanker
Robert Wanker 2020년 10월 30일
답변: Gouri Chennuru 2020년 11월 5일
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
Sindar
Sindar 2020년 10월 30일
  • What is the size of points?
  • How do you define distance?

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

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by