Question on using addedge()
18 次查看(过去 30 天)
显示 更早的评论
How do we use addedge to assign weights to a graph containing edges with multiple edge weigths(Value1 and Value2, in my example)?
tail = [1 2 3 4];
head = [2 3 4 5];
G = graph(tail,head)
G.Edges.Value1 = ones(4,1)
G.Edges.Value2 = zeros(4,1)
G = addedge(G,5,6,1) %I want to assign 1 to Value1 to the new edge created between nodes 5,6
I obtain the following error.
Error using graph/addedge (line 139)
Unable to add weighted edges to an unweighted graph.
Any suggestions?
3 个评论
采纳的回答
Jan
2018-12-14
编辑:Jan
2018-12-14
Do you mean:
G = addedge(G,5,6)
G.Edges.Value1 = ones(5,1)
Or
T = table(1, 0, 'VariableNames', {'Value1', 'Value2'});
G = addedge(G, 5, 6, T)
1 个评论
Steven Lord
2018-12-14
Or you can build a table with variables EndNodes and your custom attribute names and call addedge with the graph and the table as the two inputs. The "Add Edges with Attributes to Graph" example on the addedge documentation page shows how to do this.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!