Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to check the accessibility between two points in a matrix?

1 回表示 (過去 30 日間)
Ameer Abdullah
Ameer Abdullah 2018 年 3 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have following matrix:
board =
0 0 0 0 0 0 0 2
0 0 0 0 0 0 2 2
0 0 0 0 0 2 2 0
0 0 0 1 2 2 0 0
0 0 1 1 2 0 0 0
0 1 1 1 2 0 0 0
1 1 0 1 2 0 0 0
1 0 0 11 2 22 0 0
I need to check how many zeroes are accessible from 11 & 22 while they can't cross 2 and 1 respectively. And also is there any path between 11 and 22 keeping the same condition in view. Can anybody help?
  3 件のコメント
Ameer Abdullah
Ameer Abdullah 2018 年 3 月 21 日
accessible means that whether 22 or 11 can reach zeros traversing through their own wall(2s and 1s respectively) making horizontal and vertical moves(not diagnol). Also if 11 or 22 moves to a zero, it becomes a brick of their own wall.(11 and 22 are headers) Note that the zeros on left bottom(8,2 & 8,3) are not accessible by 22 by any means.
Walter Roberson
Walter Roberson 2018 年 3 月 21 日
"how many zeroes are accessible from 11 & 22 while they can't cross 2 and 1 respectively."
So 2 is a barrier for a path that starts from 11, and 1 is a barrier for a path that starts from 22, but 2 is not a barrier for a path that starts from 22 and 1 is not a barrier for a path that starts from 11 ? That would imply that the paths are not symmetric -- that you might be able to get from 11 to 22 but not back, or from 22 to 11 but not back. Indeed, to get from 22 to 11 you could go 22 -> 2 -> 11 because the 2 is not a barrier when starting from 2, but there is no route from 11 to 22 that does not cross the barrier of 2s that applies when starting from 11 ?

回答 (1 件)

thitch
thitch 2018 年 3 月 21 日
I would recommend implementing a simple region growing algorithm (google it), where your seed points are 11 and 22. You can keep track of each region's progress in separate logical arrays.
This should produce a logical condition for counting the number of zeros within each region. Making some assumptions about your problem, this would also provide a way of identifying the existence of a path between region '11' and region '22', e.g. something like:
% inRegion11, inRegion22 are logical arrays
if nnz(AND(inRegion11,inRegion22))
% path exists
end
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 21 日
This is generally a useful technique.
For this particular problem, I think there might be an easier method -- but first I need the poster to clarify about the blocking rules.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by