edgecount
Number of edges between two nodes
Syntax
Description
Examples
Number of Edges Between Nodes
Create a graph and display the edges table for reference. Find the number of edges between node 1 and node 2.
G = graph([1 1 1 1 2 2],[2 2 2 3 4 5]); G.Edges
ans=6×1 table
EndNodes
________
1 2
1 2
1 2
1 3
2 4
2 5
N = edgecount(G,1,2)
N = 3
You also can specify a single source node and several target nodes. Find the number of edges between node 1 and all other nodes (including self-loops).
N = edgecount(G,1,1:numnodes(G))
N = 5×1
0
3
1
0
0
Input Arguments
s,t
— Node pairs (as separate arguments)
node indices | node names
Node pairs, specified as separate arguments of node indices or node names.
Similarly located elements in s
and t
specify the source and target nodes for edges in the graph.
s
and t
must specify the same
number of nodes, unless one of them specifies a single node.
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: edgecount(G,1,2)
Example: edgecount(G,1,1:5)
Example: edgecount(G,{'a' 'b' 'c'},'a')
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The node pairs
s
andt
must be node indices of the input graphG
. Node names are not supported.
Version History
Introduced in R2018a
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)