remove nodes without changing the numbering of nodes

12 visualizaciones (últimos 30 días)
Arpit Dua
Arpit Dua el 9 de Jul. de 2020
Comentada: Steven Lord el 8 de Ag. de 2021
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 comentario
MUHAMMAD USMAN
MUHAMMAD USMAN el 7 de Ag. de 2021
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?

Iniciar sesión para comentar.

Respuesta aceptada

Akira Agata
Akira Agata el 10 de Jul. de 2020
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 comentario
Steven Lord
Steven Lord el 8 de Ag. de 2021
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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by