predecessors

Nodes that have an edge into a given node of a digraph.

Category: Mathematics > Graph and Network Algorithms

Syntax

nodes = predecessors(D, nodeID)

Returns the nodes with an edge pointing to nodeID.

Description

In a dependency graph the predecessors of a task are the tasks that must finish first. numel(predecessors(D, n)) is the in-degree of n when there are no parallel edges.

Input arguments

D
A digraph.
nodeID
A single node, as index or name.

Output arguments

nodes
Column vector of node indices (a cell array of names for a named graph), in increasing order.

Example

Who points at node 4

D = digraph([1 1 2 3 4], [2 3 4 4 5]);
predecessors(D, 4)'
successors(D, 1)'
Output
ans = 1×2

     2     3
ans = 1×2

     2     3

See also

successors inedges indegree neighbors