필터 지우기
필터 지우기

Extract subgraph using names

조회 수: 3 (최근 30일)
IrisL
IrisL 2022년 8월 25일
답변: Steven Lord 2022년 8월 25일
Hi MathWorks community,
I have a graph G which has 6119 nodes. I want to extract a subgraph H with only 539 nodes. The name of the nodes that need to be extract are in a seperate 539 x 1 double called NodeID. I tried the following code, but received 'Error using graph/subgraph (line 29) Nodes must be a vector of unique node indices, a vector of unique node names, or a logical vector of length equal to the number of nodes.'.
H = subgraph(G,strtrim(num2str(NodeID)))
I am not sure what the problem is and what should I do to resolve the problem.
For your reference, I am also attaching my G.Nodes and NodeID as a mat. file.
Thanks!
  댓글 수: 2
Matt J
Matt J 2022년 8월 25일
It would be easier to troubleshoot if you attached the actual inputs G and NodeID (in a .mat file) as opposed to a picture of them.
IrisL
IrisL 2022년 8월 25일
Thanks. Just edit my post.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2022년 8월 25일
I'd use a string array, both when naming the nodes initially and when extracting the subgraph.
B = bucky;
n = height(B);
G = graph(B, string(1:n))
G =
graph with properties: Edges: [90×2 table] Nodes: [60×1 table]
nodeIDs = randperm(n, n/4) % Extract 1/4 of the nodes
nodeIDs = 1×15
5 25 43 55 4 13 7 44 54 14 33 22 17 35 59
G2 = subgraph(G, string(nodeIDs))
G2 =
graph with properties: Edges: [5×2 table] Nodes: [15×1 table]
figure
plot(G)
title('Bucky')
figure
plot(G2)
title('Bucky/4')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by