MATLAB Answers

How to find all the edges connecting a specific node with other nodes?

조회 수: 5(최근 30일)
Rayan Glus
Rayan Glus 2021년 5월 20일
댓글: Rayan Glus 2021년 5월 21일
Let G be an undirected graph of 1000 nodes. How can I find all the edges of a specific node?
I cannot pass the node's ID as an input argument to the built-in function "findedge", so I would appreciate your help and ideas.

채택된 답변

Christine Tobler
Christine Tobler 2021년 5월 20일
Use outedges to find the IDs of all outgoing edges, or neighbors to find all nodes connected to by these edges.

추가 답변(1개)

Steven Lord
Steven Lord 2021년 5월 20일
Let's take a sample undirected graph.
G = graph(bucky);
What nodes are connected to node 51?
N = neighbors(G, 51)
N = 3×1
49 52 55
Let's plot the graph then highlight node 51 and its neighbors in the plot with large red stars instead of the small blue circles of the rest of the nodes.
h = plot(G);
highlight(h, [51; N], 'MarkerSize', 12, 'NodeColor', 'r', 'Marker', '*')
We can see that each of nodes 49, 52, and 55 are indeed connected to node 51.
  댓글 수: 1
Rayan Glus
Rayan Glus 2021년 5월 21일
Thank you so much for the great explanation.
Now, I can pass (s = 51) and its neighbors as t to built-in findedge.
Much appreciated.

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


Community Treasure Hunt

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

Start Hunting!

Translated by