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
Jan 2018년 12월 14일
According to the documentation: doc addedge
H = addedge(G,s,t,w) also specifies weights, w, for the edges between s and t.
The 4th input is the weight. It is not clear to me, what "assign 1 to Value1" means.
Deepa Maheshvare
Deepa Maheshvare 2018년 12월 14일
편집: Deepa Maheshvare 2018년 12월 14일
I meant, assigning a value of 1 to the newly added edge in the edge property named Value1 (here->G.Edges.Value1 = ones(4,1))
Deepa Maheshvare
Deepa Maheshvare 2018년 12월 14일
편집: Deepa Maheshvare 2018년 12월 14일
Let's say the graph is weighted, then H = addedge(G,s,t,w) works for Graph.Edges.Weight.
I'm trying to do the same for custom attributes (Graph.Edges.Value1) and I couldn't succeed.
Hope I was able to explain the problem

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2018년 12월 14일
편집: Jan 2018년 12월 14일

1 개 추천

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
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개)

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품

태그

질문:

2018년 12월 14일

댓글:

2018년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by