findnode

Locate node in graph

Syntax

Description

example

k = findnode(G,nodeID) returns the numeric node ID, k, of the node in graph G whose name is nodeID. The numeric node ID is zero if the node is not in the graph.

Examples

collapse all

Create a graph, and then determine the numeric node index for the nodes named 'AB' and 'BC'.

s = {'AA' 'AA' 'AA' 'AB' 'AC' 'BB'};
t = {'BA' 'BB' 'BC' 'BA' 'AB' 'BC'};
G = graph(s,t)
G = 

  graph with properties:

    Edges: [6×1 table]
    Nodes: [6×1 table]

k = findnode(G,{'AB' 'BC'})
k =

     5
     4

k contains the row index into G.Nodes.Name for each specified node.

Input Arguments

collapse all

Input graph, specified as either a graph or digraph object. Use the graph function to create an undirected graph or the digraph function to create a directed graph.

For more information, see graph or digraph.

Example: G = graph(1,2)

Example: G = digraph([1 2],[2 3])

Node names, specified as a character vector or cell array of character vectors.

Example: k = findnode(G,'Chicago') returns the numeric node ID for the node in graph G with the name, 'Chicago'.

Data Types: char | cell

Output Arguments

collapse all

Numeric node IDs, returned as a scalar or column vector. The values of k are indices into G.Nodes.Name, which is a cell array of character vectors containing the node names.

See Also

| | |

Introduced in R2015b

Was this topic helpful?