how to access value of edge weight in a biograph?
Mostra commenti meno recenti
ed=getedgesbynodeid(bgraph,'3','8'); >> wt=get(ed,'Weight'); consider the code,I want to access the value of weight of the edge? printing wt gives an empty array.
1 Commento
Abhishek
il 3 Apr 2025
Hi, did you try doing this?
get(bgraph.nodes,'ID').
This gives the list of nodes. A probable guess is that the node ID(3 and 8) are wrong. You have to check it.
Risposte (1)
Since the biograph class was removed from Bioinformatics Toolbox in release R2022b, in order to access the weight of an edge using graph or digraph, use findedge and index into the Edges table in the graph or digraph object.
rng default % Generate the same R matrix each time
% so I can select an edge I KNOW will be in the digraph
R = sprand(10, 10, 0.1);
D = digraph(R)
allEdges = D.Edges % Show the complete list of edges, so we can use it to check our answer later
E = findedge(D, 7, 9) % Which edge connects nodes 7 and 9?
weightEdge7_9 = D.Edges{E, 'Weight'} % What is the weight of that edge?
% check
edgeInformation = allEdges(E, :)
edgeInformation shows that edge 5 is in fact the edge between nodes 7 and 9 in digraph D, and the value in the Weight variable of edgeInformation matches the value in weightEdge7_9.
Categorie
Scopri di più su Graph and Network Algorithms 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!