フィルターのクリア

Finding the closest specified value in an array.

2 ビュー (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by