Digraph from two columns of data

3 visualizzazioni (ultimi 30 giorni)
Daniel Pearson
Daniel Pearson il 25 Apr 2019
Risposto: Steven Lord il 25 Apr 2019
For example, I have two columns of data in an excel sheet, Town and Time. I want to have a digraph that connects each town in the order they are given with time being the weight of the edges. Lets say that DataSet = readtable('FILE.xls').
This is probably really simple but I can't seem to work it out.

Risposte (1)

Steven Lord
Steven Lord il 25 Apr 2019
>> names = ["Boston"; "New York"; "Chicago"; "Los Angeles"; "Washington DC"];
>> D = digraph(names(1:end-1), names(2:end))
Add the weight information as the third input in the digraph call. If the data is in something like a transit schedule form (like this schedule from the MBTA's Framingham/Worcester commuter rail line) you may need to call diff on the arrival time data to get the duration of each leg of the trip. Since digraph weights can't be datetime or duration values, you'll want to convert the duration data to seconds, minutes, hours, etc. depending on the durations of the trips.

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Tag

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by