Modify the weight of few edges in Graph
조회 수: 6 (최근 30일)
이전 댓글 표시
I have the following graph with 4 edges.
tail = [1 2 3 4];
head = [2 3 4 5];
G = graph(tail,head)
G.Edges.Value = zeros(4,1)
[P,d,edgepath] = shortestpath(G,1,3)
G.Edges(edgepath,:).Value = [2 2]
The edge weights are already assigned and I want to modify it later in my code.To assign new weights to the edges between the nodes 1 and 3, I used the command shortestpath to extract the edge numbers;the last line of the code assigns new weights.
I get the following error. Any suggestions on alternate ways of modifying the edge values/weights?
Error using graph/subsasgn (line 45)
Direct editing of edges is not supported. Use addedge or rmedge instead.
댓글 수: 0
채택된 답변
Steven Lord
2018년 12월 14일
Don't try to index individual rows of the Edges table to modify properties of the edges. [You could view individual rows of the Edges table using indexing as shown in the "Add Edge Weights" example on this documentation page but you can't change them.] Access the variable inside the table then index individual rows of that variable.
G.Edges.Value(edgepath, :) = [2, 2]
G.Edges % Show the updated table
If you were doing this just so you could increase the width of the lines used to draw those edges, you could use the highlight function on the plotted graph instead.
댓글 수: 0
추가 답변 (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!