# Plotting a figure from a matrix

2 views (last 30 days)
Lewis Waswa on 30 Jun 2023
Commented: dpb on 30 Jun 2023
I have the following matrix, which describe the connection between nodes on a network. How can I plot this in Matlab?
A=[1 2; 2 3;2 4;3 5; 5 6; 6 7]
The node 1 is connected to 2, the node 2 is conncted to 3 and 4, node 3 is connected to node 5, which is conncted to 6, which is conncted to 7.
How can I plot this in matlab?
Thank you.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

dpb on 30 Jun 2023
A=[1 2; 2 3;2 4;3 5; 5 6; 6 7];
G=graph(A(:,1),A(:,2))
G =
graph with properties: Edges: [6×1 table] Nodes: [7×0 table]
plot(G)
##### 7 CommentsShow 5 older commentsHide 5 older comments
Cris LaPierre on 30 Jun 2023
Node labels have shown up by default since this function was introduced (R2015b)
dpb on 30 Jun 2023
I would have thought so, too. So wonder what's going on with OP if don't show up for him? Is there a property to turn them on/off?

Sign in to comment.

### More Answers (1)

Cris LaPierre on 30 Jun 2023
I would use digraph.
A=[1 2; 2 3;2 4;3 5; 5 6; 6 7] ;
G = digraph(A(:,1),A(:,2));
plot(G)
##### 1 CommentShow -1 older commentsHide -1 older comments
Lewis Waswa on 30 Jun 2023
Thank you @Cris LaPierre

Sign in to comment.

### Categories

Find more on Line Plots in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!