remove nodes without changing the numbering of nodes

조회 수: 2 (최근 30일)
Arpit Dua
Arpit Dua 2020년 7월 9일
댓글: Steven Lord 2021년 8월 8일
I have a graph from which I want to remove nodes but want to keep the labels or the numbering of the nodes as the same before removing nodes. Is that possible with some option?
  댓글 수: 1
MUHAMMAD USMAN
MUHAMMAD USMAN 2021년 8월 7일
When we have 100 of nodes, how can we assigned a label by writting the following command.
G = graph(s,t,[],{'1','2','3','4', ..., '100'});
There is some other way to assign a label to large-size network?

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

채택된 답변

Akira Agata
Akira Agata 2020년 7월 10일
How about setting a nodelabel for each node?
The following is an example:
s = [1 1 1 2 2 3];
t = [2 3 4 3 4 4];
% Create a graph G with nodelabel '1',...,'4'
G = graph(s,t,[],{'1','2','3','4'});
% Remove the node 1
G = rmnode(G,1);
% Plot the graph
figure
plot(G)
  댓글 수: 1
Steven Lord
Steven Lord 2021년 8월 8일
If you have too many nodes to manually create the cell array of node names, use a string array.
s = [1 1 1 2 2 3];
t = [2 3 4 3 4 4];
names = string(1:4);
% Create a graph G with nodelabel '1',...,'4'
G = graph(s,t,[], names);
G.Nodes
ans = 4×1 table
Name _____ {'1'} {'2'} {'3'} {'4'}
% Remove the node 1
G = rmnode(G,1);
% Plot the graph
figure
plot(G)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by