How do I find the number of elements of a matrix with distance n from a specific element?

1 view (last 30 days)
How do I find number of elements surrounding a specific element with a distance of n from a specific element.
For example A = [1 2 3 9;4 5 6 7; 8 9 2 3]
for the first element 1 i.e A(1,1) the number of elements with a distance of 1 is 3 (they are 2,4 and 5) and for 6 i.e A(2,3) the number is 8 ( they are 2,5,9,2,3,7,9 and 3).
for the first element 1 i.e A(1,1) the number of surrounding elements with a distance of 2 is 5 (they are 8,9,2,6 and 3) and for 6 i.e A(2,3) the number is 3 (they are 1,4 and 8).
and so on..
Any help is appreciated. Thanks.
  2 Comments
Guillaume
Guillaume on 19 Mar 2019
I don't see the significance of the numbers in the matrix.
This seems like a geometry question rather than a matlab one: how to calculate the perimeter of a clipped square.
Nitesh Suryavanshi
Nitesh Suryavanshi on 19 Mar 2019
Edited: Nitesh Suryavanshi on 19 Mar 2019
Ya thats actually what i want. I would also like to know how to get the values of the elements at these positions. Thank you.

Sign in to comment.

Answers (0)

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!