www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CreateAndModifyGraphObjectExample.m
%% Create and Modify Graph Object % Create a |graph| object with three nodes and two edges. One edge is % between node 1 and node 2, and the other edge is between node 1 and node % 3. % Copyright 2015 The MathWorks, Inc. G = graph([1 1],[2 3]) %% % View the edge table of the graph. G.Edges %% % Add node names to the graph, and then view the new node and edge tables. % The end nodes of each edge are now expressed using their node names. G.Nodes.Name = {'A' 'B' 'C'}'; G.Nodes %% G.Edges %% % You can add or modify extra variables in the |Nodes| and |Edges| tables % to describe attributes of the graph nodes or edges. However, you cannot % directly change the number of nodes or edges in the graph by modifying % these tables. Instead, use the |addedge|, |rmedge|, |addnode|, or % |rmnode| functions to modify the number of nodes or edges in a graph. % % For example, add an edge to the graph between nodes 2 and 3 and view the % new edge list. G = addedge(G,2,3) %% G.Edges