degree

Number of edges at each node of a graph.

Category: Mathematics > Graph and Network Algorithms

Syntax

d = degree(G)

Returns the degree of every node.

d = degree(G, nodeIDs)

Returns the degree of the listed nodes only.

Description

The degree of a node is the number of edges that touch it. The degrees of all nodes of an undirected graph add up to twice the number of edges, because each edge is counted at both ends.

For a digraph, indegree and outdegree give the two parts separately.

Input arguments

G
A graph. For a digraph it counts in and out edges together.
nodeIDs
Node indices or names.

Output arguments

d
Column vector of degrees.

Example

Degrees and the handshake rule

G = graph([1 1 2 3], [2 3 3 4]);
d = degree(G)'
sum(d) == 2*numedges(G)
degree(G, 3)
Output
d = 1×4

     2     2     3     1
ans = logical
   1
ans = 3

See also

indegree outdegree neighbors centrality adjacency