MATLAB can relabel graph node table columns but not edge table columns.

2 次查看(过去 30 天)
It seems that I can rename a column in the Nodes table of a graph but trying to do so for the Edges table returns an error. (This is a minimal example. It has come up in a method I'm trying to write for a user-defined class.)
g=digraph([1 2],[2 2]);
g.Nodes.label={'A';'B'}
g =
digraph with properties: Edges: [2×1 table] Nodes: [2×1 table]
g.Nodes = renamevars(g.Nodes,'label','Label')
g =
digraph with properties: Edges: [2×1 table] Nodes: [2×1 table]
g.Edges.label={'A';'B'}
g =
digraph with properties: Edges: [2×2 table] Nodes: [2×1 table]
g.Edges = renamevars(g.Edges,'label','Label')
Error using digraph/subsasgn>assignToEdges
Direct editing of edges not supported. Use addedge or rmedge instead.

Error in indexing (line 14)
G = assignToEdges(G, S, V);

采纳的回答

Jinal
Jinal 2023-3-17
编辑:Jinal 2023-3-17
Hi Roy,
I understand that you are facing issues while using ‘renamevars’ to rename a column in 'g.Edges'.
You can use the following command to rename the column.
g.Edges.Properties.VariableNames("label") = "Label";
Please refer this page for more information.
Hope this helps.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by