Outgoing edges from node
Create an undirected multigraph with three nodes and four edges. Find the outgoing edges of node 2.
G = graph([1 1 1 2],[2 2 3 3]); G.Edges
ans=4×1 table EndNodes ________ 1 2 1 2 1 3 2 3
eid = outedges(G,2)
eid = 3×1 1 2 4
eid contains indices to rows in the
G.Edges table. Use the vector to index into
ans=3×1 table EndNodes ________ 1 2 1 2 2 3
For undirected graphs, the edges (1,2) and (2,1) are the same.
Plot a graph and highlight the outgoing edges and successors of a selected node.
Create and plot a directed graph using the
bucky adjacency matrix. Highlight node 10 for reference.
G = digraph(bucky); p = plot(G); highlight(p,10,'NodeColor','r','MarkerSize',10)
Determine the outgoing edges and successors of node 10. Highlight these nodes and edges.
[eid,nid] = outedges(G,10)
eid = 3×1 28 29 30
nid = 3×1 6 9 12
X = G.Edges(eid,:)
X=3×2 table EndNodes Weight ________ ______ 10 6 1 10 9 1 10 12 1
nodeID— Node identifier
Node identifier, specified as one of the values in this table.
|Scalar node index|
|Character vector node name|
|String scalar node name|
eid— Edge indices
Edge indices, returned as a column vector. You can use the edge indices to
index into the edges table of the graph with
nid— Node IDs of successors
Node IDs of successors, returned as node indices if
nodeID is numeric, or as node names if
nodeID is a node name. Use
findnode(G,nid) to convert node names into node
indices. You can use node indices to index into the nodes table of the graph
The node IDs in
nid are the same as those returned by
successors function. However, if there are multiple
outgoing edges to the same node, this node is listed more than once in
By convention, for undirected graphs, all edges incident to a node are
considered to be outgoing edges. Use
inedges to find incoming edges in a directed graph.
For graphs with multiple edges,
successors can return arrays of different lengths,
since there can be multiple outgoing edges to some of the successors.