neighbors
Neighbors of graph node
Syntax
Description
Examples
Neighboring Graph Nodes
Create and plot a graph, and then determine the neighbors of node 10
.
G = graph(bucky); plot(G)
N = neighbors(G,10)
N = 3×1
6
9
12
Input Arguments
G
— Input graph
graph
object
Input graph, specified as a graph
object. Use graph
to create an undirected graph object.
Example: G = graph(1,2)
nodeID
— Node identifier
node index | node name
Node identifier, specified as one of the values in this table.
Value | Example |
---|---|
Scalar node index | 1 |
Character vector node name | 'A' |
String scalar node name | "A" |
Example: N = neighbors(G,3)
Example: N = neighbors(G,'A')
Output Arguments
N
— Neighboring nodes
node indices | node names
Neighboring nodes, returned as node indices if nodeID
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.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The node identifier
nodeID
must be a scalar node index of the input graphG
. Node names are not supported.
Version History
Introduced in R2015bR2018a: Self-loop counting change
neighbors
counts self-loops only once. In previous releases,
if node u
had a self-loop, then neighbors(g,u)
listed u
twice in the output. neighbors(g,u)
now returns only one instance of u
.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)