www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AddNodesWithAttributesExample.m

    %% Add Nodes with Attributes to Graph
% Create a graph whose nodes represent airports.

% Copyright 2015 The MathWorks, Inc.

G = graph({'JFK' 'LAX'}, {'LAX' 'DEN'})

%%
% Add a node attribute to indicate whether each airport has free WIFI.
G.Nodes.WIFI = [false true true]';
G.Nodes

%%
% Add two new nodes to the graph by creating a table, |NodeProps|,
% containing the node name and WIFI status of each new node. Use |addnode|
% to concatenate |NodeProps| to |G.Nodes|.
NodeProps = table({'ATL' 'ANC'}', [false true]', ...
    'VariableNames', {'Name' 'WIFI'});
G = addnode(G, NodeProps);

%%
% View the modified node table.
G.Nodes