How to label all the edges in a graph the euclidean distance between two adjacent nodes???
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Bhat
el 17 de Mzo. de 2019
Comentada: Mohammad Bhat
el 18 de Mzo. de 2019
Hi,
I have to weight each edge in below attached undirected graph with euclidean distance between two adjacent nodes. How we can do that???
0 comentarios
Respuesta aceptada
Akira Agata
el 18 de Mzo. de 2019
I think one possible solution would be like this:
% Make Graph object
rng('default');
s = [1 1 3];
t = [2 3 4];
G = graph(s,t);
% Calculate pair-wise Euclidian distance between every node
X = 10*rand(4,1);
Y = 10*rand(4,1);
d = pdist([X,Y]);
d = squareform(d);
% Label Euclidian distance for each edge
G.Edges.Wieght =...
arrayfun(@(j,k) d(j,k),G.Edges.EndNodes(:,1),G.Edges.EndNodes(:,2));
% Visualize the Graph
plot(G,'XData',X,'YData',Y,'EdgeLabel',G.Edges.Wieght)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Graph and Network Algorithms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!