Accessing surrounding elements in an array

20 ビュー (過去 30 日間)
pavan pal
pavan pal 2018 年 11 月 21 日
回答済み: TADA 2018 年 11 月 22 日
I have been given a random square matrix and each element in the matrix has 8 surrounding elements called their "neighbors". I am struggling to write code on how to access these neighbors. For this matrix if i was to access the neighbors of A(3,2) the the neighbors are the 8 surrounding elements. If it was A(1,1) the neighbors would be A(2,1) A(2,2) A(1,2) A(5,1) A(1,5) A(2,5) A(5,2) and A(5,5). Any help would be appreciated.
A= 1 2 1 1 1
1 2 0 0 2
1 2 0 0 1
0 0 2 0 1
1 2 1 1 1

回答 (1 件)

TADA
TADA 2018 年 11 月 22 日

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by