Main Content


Outgoing edges from node



eid = outedges(G,nodeID) returns the indices of all outgoing edges from node nodeID in graph G.


[eid,nid] = outedges(G,nodeID) additionally returns the successor nodes nid that are connected to nodeID by the edges eid.


collapse all

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]);
ans=4×1 table

     1    2 
     1    2 
     1    3 
     2    3 

eid = outedges(G,2)
eid = 3×1


The vector eid contains indices to rows in the G.Edges table. Use the vector to index into G.Edges.

ans=3×1 table

     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);

Figure contains an axes object. The axes object contains an object of type graphplot.

Determine the outgoing edges and successors of node 10. Highlight these nodes and edges.

[eid,nid] = outedges(G,10)
eid = 3×1


nid = 3×1


X = G.Edges(eid,:)
X=3×2 table
    EndNodes    Weight
    ________    ______

    10     6      1   
    10     9      1   
    10    12      1   


Figure contains an axes object. The axes object contains an object of type graphplot.

Input Arguments

collapse all

Input graph, specified as either a graph or digraph object. Use graph to create an undirected graph or digraph to create a directed graph.

Example: G = graph(1,2)

Example: G = digraph([1 2],[2 3])

Node identifier, specified as one of the values in this table.

Scalar node index1
Character vector node name'A'
String scalar node name"A"

Example: outedges(G,1)

Example: outedges(G,'A')

Output Arguments

collapse all

Edge indices, returned as a column vector. You can use the edge indices to index into the edges table of the graph with G.Edges(eid,:).

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 with G.Nodes(nid,:).

The node IDs in nid are the same as those returned by the successors function. However, if there are multiple outgoing edges to the same node, this node is listed more than once in nid.


  • 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, outedges and successors can return arrays of different lengths, since there can be multiple outgoing edges to some of the successors.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2018a