H = addnode(G,numNodes)
adds a number of new nodes to G equal to
numNodes. If G contains nodes with names,
then the new nodes are assigned sequential names indicating their row placement in
G.Nodes.Name. For example, 'Node5' is
located at G.Nodes.Name(5).
H = addnode(G,NodeProps)
adds new nodes to G with the node properties in
NodeProps. One node is added for each row in
NodeProps. The NodeProps table must be
able to be concatenated to G.Nodes, so that the result is
H.Nodes = [G.Nodes; NodeProps].
Add two nodes to a graph that does not have node names.
G = graph([1 2 3],[2 3 4])
G =
graph with properties:
Edges: [3x1 table]
Nodes: [4x0 table]
G = addnode(G,2)
G =
graph with properties:
Edges: [3x1 table]
Nodes: [6x0 table]
Add node names to the graph, and then add five additional new nodes. The auto-generated names for the new nodes indicate their placement in G.Nodes.Name.
G.Nodes.Name = {'A''B''C''D''E''F'}'
G =
graph with properties:
Edges: [3x1 table]
Nodes: [6x1 table]
Add two new nodes to the graph by creating a table, NodeProps, containing the node name and Wi-Fi status of each new node. Use addnode to concatenate NodeProps to G.Nodes.
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])
nodeIDs — Node names one or more node names
Node names, specified as one or more node names in one of these forms:
Single Node — Character
vector 'A' or string scalar
"A".
Multiple Nodes — Cell array
of character vectors {'A' 'B' 'C'} or string
array ["A" "B" "C"].
Example: H = addnode(G,'A')
Example: H = addnode(G,["A" "B" "C"])
Data Types: char | cell | string
numNodes — Number of nodes to add nonnegative numeric scalar
Number of nodes to add, specified as a nonnegative numeric scalar.
NodeProps — Node attributes table
Node attributes, specified as a table. NodeProps can
contain any number of variables to describe attributes of the graph nodes,
but must be able to be concatenated to G.Nodes, so that
the result is H.Nodes = [G.Nodes; NodeProps]. For node
names, use the variable Name, since this variable name is
used by some graph functions. If there is a variable
Name, then it must be a cell array of character vectors
or string array specifying a unique name in each row. See table for more information
on constructing a table.
Output graph, returned as a graph or digraph object.
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The input argument nodeIDs that specifies node
names is not supported.
You cannot add new variables, or new columns, to the
G.Nodes table after the graph object is
created.
When you construct a graph or
digraph object in MATLAB® and pass it to a MEX function generated using MATLAB
Coder™, you cannot add nodes to the graph object.
The node properties must be data types that can be stored as
variable-size arrays in code generation. For example, the data type
cannot be any of these:
a string array
a cell array with different sizes on each cell
a cell array of character vectors converted using
cellstr
a user-defined class
Thread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.
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.