Documentation

indegree

In-degree of nodes

Syntax

D = indegree(G)
D = indegree(G,nodeIDs)

Description

example

D= indegree(G)returns a column vector containing the in-degree of each node inG.

example

D= indegree(G,nodeIDs)returns the in-degree of the nodes specified bynodeIDs.

Examples

collapse all

Create and plot a directed graph, and then compute the in-degree of every node in the graph. The in-degree of a node is equal to the number of edges with that node as the target.

s = [1 3 2 2 4 5 1 2]; t = [2 2 4 5 6 6 6 6]; G = digraph(s,t); plot(G)

indeg = indegree(G)
indeg =0 2 0 1 1 4

indeg(j)indicates the in-degree of nodej.

Create and plot a directed graph with named nodes. Then compute the number of edges that have the'a','b', and'f'nodes as their target.

s = {'a''c''b''b''d''e''a''b'}; t = {'b''b''d''e''f''f''f''f'}; G = digraph(s,t); plot(G)

nodeID = {'a''b''f'}'; indeg = indegree(G,nodeID)
indeg =0 2 4

indeg(j)indicates the in-degree of nodenodeID(j).

Input Arguments

collapse all

Input graph, specified as adigraphobject. Usedigraphto create a directed graph object.

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

Node identifiers, specified as a scalar node index, a vector or matrix of numeric node indices, a character vector node name, or a cell array of character vectors containing node names. You can refer to the nodes either by their numeric node index or by their node names.

Output Arguments

collapse all

In-degree of nodes, returned as a numeric array.Dis a column vector unless you specifynodeIDs, in which caseDhas the same size asnodeIDs.

The in-degree of a graph node is equal to the number of predecessors, such thatindegree(G,ind) == length(predecessors(G,ind)).

Introduced in R2015b

Was this topic helpful?