Coordinates/values around number in array
1 次查看(过去 30 天)
显示 更早的评论
Hello
Say I want to choose a value in an array and I want to find the value of the elements that surround them. Say the number i pick is 2 in the array below. I know I could find all the 2's and look north south east and west of each 2 in the array. I just wanted to know if there was a more elegent way
thank you
Andrew
3 1 1 1 1 %let say I pick "2", so the elements are 1,3,1,1,1,1,1,4
3 3 1 1 1
3 1 2 2 1
1 3 2 7 1
1 1 2 4 1
0 个评论
回答(1 个)
KSSV
2022-5-8
If (i,j) is the index of number 2; then the nearest elements to it will be (i-1,j),(i+1,j),(i,j+1),(i,j-1),(i+1,j-1),(i+1,j+1),(i-1,j-1),(i-1,j+1).
Also have a look on knnsearch, rangesearch.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!