Implement edges weights from nodes variables
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
I have a digraph G (see attached file) , with all nodes having a certain value of the variable “TempsD”. I would like to implement an algorithm that for every out-edges of node (i) their weights are equal to the variable value “TempsD” of node (i). This should be done for all edges of G.
How can I do that?
Thanks in advance
0 comentarios
Respuestas (1)
Satyam
el 17 de Jun. de 2025
Hi Fabio,
According to my understanding, we can implement an algorithm that for every out-edge of a source node, assigns the weight equal to the value of the variable 'TempsD' for that node.
This problem can be solved using an algorithm which iterates through each edge, retrieves the name of the source node from the first entry in the 'EndNodes' pair, and then looks up the corresponding 'TempsD' value from the Nodes table. This value is then assigned as the new weight for the edge. After processing all edges, the updated weights are stored in the 'Weight' column of the 'Edges' table.
You can refer to the following documentation of ‘digraph’ to learn more about different properties and their appropriate syntax: https://www.mathworks.com/help/matlab/ref/digraph.html
Here is a sample code snippet demonstrating the above approach:
% Loop through each edge
for k = 1:height(G.Edges)
% Get source node name from EndNodes
sourceNode = G.Edges.EndNodes{k,1}; % First column is source in digraph
% Find corresponding TempsD value from Nodes
tempsD = G.Nodes.TempsD(strcmp(G.Nodes.Name, sourceNode));
% Assign the value to the weight
newWeights(k) = tempsD;
end
I hope this algorithm satisfies the query.
0 comentarios
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!