Assigning arrays to edge properties of a graph
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to assign arrays to edge properties/weights
tail = 1:3;
head = 2:4;
G = graph(tail,head);
G.Edges.property(1) = 1 % works
G.Edges.property(1) = [1 2] % doesn't work
However , I get the following error while trying to assign an array to a single edge
Unable to perform assignment because the left and right sides have a different number of elements.graph
Is there an alternate way to store array for each edge?
0 个评论
采纳的回答
Steven Lord
2019-12-13
A two-element vector like [1 2] doesn't fit into one element of an array like G.Edges.property.
If you were assigning the vector to the edge property first, this would work:
>> G = graph(tail,head);
>> G.Edges.property(1, :) = [1 2]
>> G.Edges % Check
But if you'd already assigned a scalar to the first element of property that won't work.
>> G = graph(tail,head);
>> G.Edges.property(1) = 1;
>> G.Edges.property(1, :) = [1 2];
Error using graph/subsasgn (line 52)
Unable to perform assignment because the size of the left side is 1-by-1
and the size of the right side is 1-by-2.
I manually line broke the error message to avoid scrolling.
In this case, you need to explicitly state that you want to assign into a piece of property that has two columns.
>> G.Edges.property(1, 1:2) = [1 2];
>> G.Edges % Check
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!