Using accumarray to sum all values associated with a given node
2 views (last 30 days)
Show older comments
Given a graph with the following edges
edges = [1 2; 2 3; 3 1; 2 4; 4 5; 4 1];
I have some data associated with each edge
data=[0.276
0.679
0.655
0.162
0.118
0.333];
For a given node, I want to sum the data values corresponding to all edges it's connected to. How do I do this? accumarray looks promising, but this gives six nonzero values, when there should just be 5 (and I don't know how to distinguish which one corresponds to which node).
sum_data = accumarray(edges,data);
0 Comments
Accepted Answer
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!