フィルターのクリア

I want to find whether the selected elements of a matrix are adjacent or not?

1 回表示 (過去 30 日間)
Amir
Amir 2015 年 4 月 5 日
編集済み: Matt J 2015 年 4 月 6 日
For e,g
A=[0 1 1 0;
0 1 0 0]
i have selected A(1,2), A(1,3), A(2,2) for use , i want to know that which pair is adjacent to other ?
  3 件のコメント
Amir
Amir 2015 年 4 月 6 日
i want to know through their indices i.e A(1,2) A(1,3) are adjacent while A(1,2) and A(2,2) are also adjacent , so if I have these matrix indices, i want to check which index position is adjacent to other ?
Image Analyst
Image Analyst 2015 年 4 月 6 日
That's not what I asked. I want to know if you consider A(2,2) "adjacent" to A(1,3) because there is a path of 1's connecting them. If so, you can simply use bwlabel.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2015 年 4 月 6 日
If you have two locations: row1, col1 and row2, col2, then they are immediately adjacent (1 layer away) if
if abs(row1-row2) <= 1 && abs(col1-col2) <= 1
% Adjacent
else
% Not adjacent
end

その他の回答 (1 件)

Matt J
Matt J 2015 年 4 月 5 日
編集済み: Matt J 2015 年 4 月 5 日
How about computing an adjacency matrix.
[i,j]=find(A);
AdjacencyMatrix = xor( abs(bsxfun(@minus,i,i.'))==1 , abs(bsxfun(@minus,j,j.'))==1 )
Don't know if you want to allow diagonal adjacency. The above assumes not.
  2 件のコメント
Amir
Amir 2015 年 4 月 6 日
Sorry , i don't need that ! i need an algorithm to find whether particular indices of a matrix are adjacent? For eg. how to know that A(1,2) and A(1,3) are horizontally adjacent and A(1,2) A(2,2) are vertically adjacent ??
Matt J
Matt J 2015 年 4 月 6 日
編集済み: Matt J 2015 年 4 月 6 日
Yep. The adjacency matrix carries that information. Each row/column represents a point. If an entry is 1, it means the pair of points represented by that row/column are adjacent.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by