select subgraph from graph
2 ビュー (過去 30 日間)
古いコメントを表示
Dear All,
i have a graph such as
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21];
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W)
i need to select subgraph for only some nodes such as [6,2,4]
thanks in advance hassan
0 件のコメント
回答 (1 件)
ag
2024 年 9 月 15 日
Hi Hassan,
To construct a subgraph containing the specified nodes, you can use the MATLAB function "subgraph". The "subgraph" function requires a "graph" object, which can be created by using the "digraph" function applied to the specified sparse adjacency matrix.
The following code snippet illustrates the above workflow:
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21];
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W)
%Create a graph object for the given DG matrix
G = digraph(DG);
% Specify the nodes for the subgraph
selectedNodes = [6, 2, 4];
% Create the subgraph containing only the specified nodes
subG = subgraph(G, selectedNodes)
plot(subG,'EdgeLabel', subG.Edges.Weight);
Please note, that the node numbering in the subgraph is reset.
For more details, please refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/graph.subgraph.html#:~:text=The%20node%20numbering%20in%20the%20subgraph%20is%20reset
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!