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?

采纳的回答

Steven Lord
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 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by