How created a graph from unordered node list?
Ältere Kommentare anzeigen
I want to created a graph from an unordered list of nodes. However, Matlab creat graph from ordered node numbers. For example, My node list is as :
source=[1,4,8,7];
Target=[7,8,1,4];
Now this would be the result if I plot the graph from this source and target nodes:
G=graph(source,Target);
P=plot(G);

The results shows the range of nodes from 1 to 8; however, These nodes don't exist in this network. This is problematic since I have a huge road network like this (34000 unordered pairs of source and targets) and each node has and coordiantion. This seroiusly cause problem while I'm trying to plot it with coordiantes. I tried to remove those nodes but it completly changes the graph (I have no Idea why this happening). Thank you in advance for any advice or help.
Akzeptierte Antwort
Weitere Antworten (1)
darova
am 6 Apr. 2020
Try this
x = x(:);
y = y(:);
plot([x(source) x(target)],[y(source) y(tagrget)])
or patch function
fv.vertices = [x(:) y(:)];
fv.faces = [source(:) target(:)]];
patch(fv)
5 Kommentare
Mohammad Shapouri
am 6 Apr. 2020
Bearbeitet: Mohammad Shapouri
am 6 Apr. 2020
darova
am 6 Apr. 2020
Can you be more specific? Can you attach the data you tried?
Mohammad Shapouri
am 6 Apr. 2020
darova
am 6 Apr. 2020
Can you attach small part of the data or simplified example?
Mohammad Shapouri
am 6 Apr. 2020
Kategorien
Mehr zu Networks finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!