Get neighbours of an element in matrix

4 次查看(过去 30 天)
pb1106
pb1106 2020-4-5
评论: dpb 2020-4-5
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 个评论
dpb
dpb 2020-4-5
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labyrinth problems 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by