outdegree
Out-degree of nodes
Description
Examples
Out-degree of All Graph Nodes
Create and plot a directed graph, and then compute the out-degree of every node in the graph. The out-degree of a node is equal to the number of edges with that node as the source.
s = [1 3 2 2 4 5 1 2]; t = [2 2 4 5 6 6 6 6]; G = digraph(s,t); plot(G)
outdeg = outdegree(G)
outdeg = 6×1
2
3
1
1
1
0
outdeg(j)
indicates the out-degree of node j
.
Out-degree of Subset of Graph Nodes
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 source.
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'}'; outdeg = outdegree(G,nodeID)
outdeg = 3×1
2
3
0
outdeg(j)
indicates the out-degree of node nodeID(j)
.
Input Arguments
G
— Input graph
digraph
object
Input graph, specified as a digraph
object. Use digraph
to create a directed graph object.
Example: G = digraph([1 2],[2 3])
nodeIDs
— Node identifiers
node indices | node names
Node identifiers, specified as one or more node indices or node names.
This table shows the different ways to refer to one or more nodes either by their numeric node indices or by their node names.
Form | Single Node | Multiple Nodes |
---|---|---|
Node index | Scalar Example: | Vector Example: |
Node name | Character vector Example: | Cell array of character vectors Example: |
String scalar Example: | String array Example: |
Example: outdegree(G,1)
Example: outdegree(G,["A" "B" "C"])
Output Arguments
D
— Out-degree of nodes
array
Out-degree of nodes, returned as a numeric array. D
is
a column vector unless you specify nodeIDs
, in which case
D
has the same size as
nodeIDs
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The node identifiers
nodeIDs
must be one or more node indices of the input graphG
. Node names are not supported.
Version History
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)