Modify the weight of few edges in Graph
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Deepa Maheshvare
am 14 Dez. 2018
Beantwortet: Steven Lord
am 14 Dez. 2018
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 Kommentare
Akzeptierte Antwort
Steven Lord
am 14 Dez. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!