how to access value of edge weight in a biograph?

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

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.

Accedi per commentare.

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)
D =
digraph with properties: Edges: [9x2 table] Nodes: [10x0 table]
allEdges = D.Edges % Show the complete list of edges, so we can use it to check our answer later
allEdges = 9x2 table
EndNodes Weight ________ ________ 1 2 0.65574 2 10 0.035712 3 5 0.84913 6 10 0.93399 7 9 0.67874 9 2 0.75774 10 5 0.74313 10 8 0.39223 10 10 0.65548
E = findedge(D, 7, 9) % Which edge connects nodes 7 and 9?
E = 5
weightEdge7_9 = D.Edges{E, 'Weight'} % What is the weight of that edge?
weightEdge7_9 = 0.6787
% check
edgeInformation = allEdges(E, :)
edgeInformation = 1x2 table
EndNodes Weight ________ _______ 7 9 0.67874
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

Richiesto:

S M
il 13 Ott 2016

Risposto:

il 3 Apr 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by