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.

findnode

Locate node in graph

Syntax

k = findnode(G,nodeID)

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: [6x1 table]
    Nodes: [6x1 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 graph to create an undirected graph or digraph to create a directed graph.

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.

Introduced in R2015b

Was this topic helpful?