How to make complete graph from co-ordinates.
Mostra commenti meno recenti
x=[0.3 ,5.6 , -8.4,6.4 ] % These are my x-cordinates
y=[4.6, 6.9,3.6,7.89]% These are my y-cordinates
I want to plot complete undirected graph with edge weight in between nodes.
Risposta accettata
Più risposte (3)
x=[0.3 ,5.6 , -8.4,6.4 ] % These are my x-cordinates
y=[4.6, 6.9,3.6,7.89]% These are my y-cordinates
nx = length(x);
CG = ones(nx, nx);
CG(1:nx+1:end) = 0;
G = graph(CG)
plot(G, 'XData', x, 'YData', y)
5 Commenti
Ashish Verma
il 12 Ago 2021
Modificato: Ashish Verma
il 12 Ago 2021
Walter Roberson
il 12 Ago 2021
G.Edges.Weight = (a column vector);
plot(G, 'XData', x, 'YData', y, 'EdgeLabel', G.Edges.Weight)
x=[0.3 ,5.6 , -8.4,6.4 ] % These are my x-cordinates
y=[4.6, 6.9,3.6,7.89]% These are my y-cordinates
nx = length(x);
CG = ones(nx, nx);
CG(1:nx+1:end) = 0;
G = graph(CG);
G.Nodes.Names = {'A', 'B', 'C', 'D'}.';
G.Edges.Weight = round(rand(height(G.Edges),1),2); %use real data here!
plot(G, 'XData', x, 'YData', y, 'EdgeLabel', G.Edges.Weight);
Ashish Verma
il 12 Ago 2021
x =[0.3 ,5.6 , -8.4,6.4 ] % These are my x-cordinates
y =[4.6, 6.9,3.6,7.89]% These are my y-cordinates
dists = squareform(pdist([x(:), y(:)]));
[s, t, w] = find(dists);
G = graph(s, t, round(w,2));
G.Nodes.Names = {'A', 'B', 'C', 'D'}.';
plot(G, 'XData', x, 'YData', y, 'EdgeLabel', G.Edges.Weight, 'NodeLabel', G.Nodes.Names);
Ashish Verma
il 12 Ago 2021
0 voti
Ashish Verma
il 12 Ago 2021
0 voti
Categorie
Scopri di più su Process Point Clouds in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



