Coordinates/values around number in array

1 visualización (últimos 30 días)
Andrew Luce
Andrew Luce el 8 de Mayo de 2022
Respondida: KSSV el 8 de Mayo de 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

Respuestas (1)

KSSV
KSSV el 8 de Mayo de 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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by