Clear Filters
Clear Filters

Coordinates/values around number in array

1 view (last 30 days)
Andrew Luce
Andrew Luce on 8 May 2022
Answered: KSSV on 8 May 2022
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

Answers (1)

KSSV
KSSV on 8 May 2022
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.

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!