addnode
Adds nodes to a graph or digraph.
Category: Mathematics > Graph and Network Algorithms
Syntax
H = addnode(G, N)
Appends N unnamed nodes.
H = addnode(G, names)
Appends one node per name in the cell array or character vector names.
Description
The new nodes are isolated: they have no edges until you add some with addedge. They receive the next indices after the existing nodes.
To name the nodes of a graph, build it with names from the start or add named nodes to a graph that already has names.
Input arguments
G- A
graphordigraph. N- Number of nodes to add.
names- Names for the new nodes: a character vector, or a cell array of them.
Output arguments
H- Graph with the extra nodes and the same edges as
G.
Example
Isolated nodes
G = graph([1 2], [2 3]);
H = addnode(G, 2);
disp([numnodes(H) numedges(H)])
disp(degree(H)')
N = graph({'a','b'}, {'b','c'});
N = addnode(N, 'z');
disp(N.Nodes.Name')
Output
5 2
1 2 1 0 0
{'a'} {'b'} {'c'} {'z'}