MATLAB: Plotting an undirected graph with weights

MATLABundirected graphweights

I have a set of 50 nodes with x and y coordinates and have a 50×50 matrix with the travel demands between each node pair. For each pair it holds that the demand is the same in both directions. I am trying to figure out how to plot the nodes with edges between each pair, where the color gives an indication on the weight of the edge (based on the value of travel demand). Does anybody know of a good way to plot this?

Best Answer

Use the graph and network algorithms functionality included in MATLAB. Call graph to build your graph object then call plot on the graph object to visualize it. See the "Custom Graph Node Coordinates" and "Edge Line Width Proportional to Edge Weight" examples on the plot documentation page for more information on how to control the locations of the nodes in the plot and how to customize properties on a per-edge basis.
[Edited to add] If you want to keep your coordinates as part of the graph object rather than as separate arrays that could be accidentally clear-ed, store them as part of the Nodes table in the graph object as shown on this documentation page.
Related Question