How can you visualize graphs with string-labeled edges?

조회 수: 6 (최근 30일)
Paolo Binetti
Paolo Binetti 2018년 5월 10일
답변: Abhishek 2025년 4월 4일
With the biograph function you can generate a graph object, which you can then visualize with the view function. But it seems this method can only handle graphs with edges labeled with numbers (weigths), not chars or strings. Is there any way I can easily view such a graph with Matlab?

답변 (1개)

Abhishek
Abhishek 2025년 4월 4일
Hello Paolo,
Since the biograph class was removed from the Bioinformatics Toolbox in release R2022b, to visualize graphs with edges labelled using characters or strings in MATLAB, you can use the graph or digraph classes. These classes allow you to add custom attributes to nodes and edges, which can include string labels.
Here is the step-by-step implementation of solving the problem using the ‘digraph’ class. I have tried it in MATLAB R2024b.
  1. Create a Directed Graph: First thing first, you need to define the source(s) and the target(t) nodes for you directed graph:
s = [1 1 2 2 3];
t = [2 4 3 4 4];
G = digraph(s, t);
2. Add edge labels: Add a custom attribute to the edges to label them with strings:
G.Edges.Label = {'A', 'B', 'C', 'D', 'E'}';
3. Visualize the Graph: Using the ‘plot’ method, you can visualize the graph:
p = plot(G, 'EdgeLabel', G.Edges.Label);
The above implementation ensures a correct representation labelling the edges with string type data.
I hope this helps to solve your problem. Thanks.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by