Get neighbours of an element in matrix

4 views (last 30 days)
pb1106
pb1106 on 5 Apr 2020
Commented: dpb on 5 Apr 2020
Hello,
Is there some easy way to get all the pixels of an element from a matrix?
For example. given the following matrix:
M=[0 0 1 1;
1 0 0 1;
1 0 0 1;
1 1 0 0];
the neighbours of M(1,1) are 0 and 1 ,the neighbours of M(1,2) are 0 0 and 1, etc
What I want to do with this information: M is a "maze matrix" where 1 is wall and 0 is a valid path. From this matrix I want to create an adjacency matrix(where the 0 elements from M will be the nodes) to perform some search algorithms.
I am gratefull for any idea. Thank you!
  1 Comment
dpb
dpb on 5 Apr 2020
Given an i,j it's simply i+/-1,j+/-1 keeping track of boundaries so if i,j --> 1 or end only have the + or - side, respectively.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!