Get neighbours of an element in matrix
4 views (last 30 days)
Show older comments
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
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.
Answers (0)
See Also
Categories
Find more on Labyrinth problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!