Neighbors of graph node
Neighboring Graph Nodes
Create and plot a graph, and then determine the neighbors of node
G = graph(bucky); plot(G)
N = neighbors(G,10)
N = 3×1 6 9 12
nodeID — Node identifier
node index | node name
Node identifier, specified as one of the values in this table.
|Scalar node index|
|Character vector node name|
|String scalar node name|
N = neighbors(G,3)
N = neighbors(G,'A')
N — Neighboring nodes
node indices | node names
Neighboring nodes, returned as node indices if
is numeric, or as node names if
nodeID is a node name. A
node that is connected to itself by an edge (a self-loop) is listed as its
own neighbor only once.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The node identifier
nodeIDmust be a scalar node index of the input graph
G. Node names are not supported.
Version HistoryIntroduced in R2015b
R2018a: Self-loop counting change
Behavior changed in R2018a
neighbors counts self-loops only once. In previous releases,
u had a self-loop, then
u twice in the output.
now returns only one instance of