Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

neighbors

Neighbors of graph node

Syntax

N = neighbors(G,nodeID)

Description

example

N = neighbors(G,nodeID) returns the node IDs of all nodes connected by an edge to the node specified by nodeID.

Examples

collapse all

Create and plot a graph, and then determine the neighbors of node 10.

G = graph(bucky);
plot(G)

N = neighbors(G,10)
N = 

     6
     9
    12

Input Arguments

collapse all

Input graph, specified as a graph object. Use graph to create an undirected graph object.

Example: G = graph(1,2)

Node identifier, specified as a scalar node index or character vector node name.

Example: N = neighbors(G,3)

Example: N = neighbors(G,'A')

Output Arguments

collapse all

Neighboring nodes, returned as a column vector of node indices. A node that is connected to itself by an edge (a self-loop) is listed as its own neighbor twice, and the self-loop adds 2 to the total degree of the node.

See Also

| |

Introduced in R2015b

Was this topic helpful?