# find commun neighbor of matrix

조회 수: 3 (최근 30일)
khaled nouri 2017년 5월 30일
답변: Santhana Raj 2017년 6월 1일
Hello, I have a graph which is represented by this matrix A =[0 1 0 1; 1 0 0 0; 0 1 0 0; 1 0 1 0;]
i went to search the no nodes of matrix which have a commun neighbor, for exemple node 1 is connected with [2,4] and node 2 is connected with [1, 4] so nodes 1 and 2 have a commun neighbor which is node 4
can you Help me PLEASE? ^-^
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Santhana Raj 2017년 5월 31일
If the matrix you have given is a node connectivity matrix, doesn't this has to be symmetric??
Walter Roberson 2017년 5월 31일
Not for directed graphs it does not need to be symmetric.
"having a common neighbor" in a directed graph situation does not promise that the nodes are reachable from each other. For example node 4 might have directed links only towards nodes 1 and 2, with there being way to get from node 1 to node 2 by way of node 4.

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Santhana Raj 2017년 6월 1일
From my understanding of nodes,
A =[0 1 0 1; 1 0 0 0; 0 1 0 0; 1 0 1 0;]
h=zeros(4);
for i=1:4
[~,H]=find(A(i,:)==1);
h(i,1:length(H))=H;
end
neigh=[];
for i=1:4
if numel(nonzeros(h(:)==i))>1
neigh=[neigh i];
end
end
this seems to work.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Nearest Neighbors에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by