Using graph plot, the nodes are assigned numbers from 1: n. How to rename all the 'n; nodes

1 件のコメント

KSSV
KSSV 2021 年 12 月 22 日
Any example to demonstrate?

サインインしてコメントする。

 採用された回答

Steven Lord
Steven Lord 2021 年 12 月 22 日

0 投票

Let's take a sample graph and look at it.
[B, V] = bucky;
B10 = B(1:10, 1:10);
V10 = V(1:10, :);
G = graph(B10);
plot(G, 'XData', V10(:, 1), 'YData', V10(:, 2), 'ZData', V10(:, 3));
Look at the Nodes table of the graph G.
G.Nodes
ans = 10×0 empty table
If that table had a variable Name, those would be the names of the nodes. [See the Add Node Names section on this documentation page.] If it did you could modify one element of that variable to change the name of one node. In this case since it doesn't have that variable you can add it to the table.
G2 = G;
G2.Nodes.Name = ["alpha"; "beta"; "gamma"; "delta"; "epsilon"; ...
"zeta"; "eta"; "theta"; "iota"; "kappa"];
figure
plot(G2, 'XData', V10(:, 1), 'YData', V10(:, 2), 'ZData', V10(:, 3));
G2.Nodes
ans = 10×1 table
Name ___________ {'alpha' } {'beta' } {'gamma' } {'delta' } {'epsilon'} {'zeta' } {'eta' } {'theta' } {'iota' } {'kappa' }
Or if you just wanted to change the labels in the plot, use labelnode.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraph and Network Algorithms についてさらに検索

製品

リリース

R2021b

質問済み:

2021 年 12 月 22 日

回答済み:

2021 年 12 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by