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.

 採用された回答

dpb
dpb 2023 年 6 月 30 日

0 投票

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 件のコメント

Lewis Waswa
Lewis Waswa 2023 年 6 月 30 日
Thank you. This worked. I however could not get my plot to produce the node numbers
dpb
dpb 2023 年 6 月 30 日
編集済み: dpb 2023 年 6 月 30 日
Well, does by default as shown for later releases...what release are you running?
You can also try digraph as did @Cris LaPierre to see if it behaves any differently with it.
Cris LaPierre
Cris LaPierre 2023 年 6 月 30 日
Will also add a digraph just indicates direction (arrows on the lines)
Lewis Waswa
Lewis Waswa 2023 年 6 月 30 日
Matlab 2022b
dpb
dpb 2023 年 6 月 30 日
First time I ever executed it so wasn't aware, @Cris LaPierre :)
My machine died and haven't gotten the updated license file for the rarely used laptop dealt with what with trying to resurrect the other, so can't try anything here.
When should node numbers have begun showing up, @Cris LaPierre?
Cris LaPierre
Cris LaPierre 2023 年 6 月 30 日
Node labels have shown up by default since this function was introduced (R2015b)
dpb
dpb 2023 年 6 月 30 日
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?

サインインしてコメントする。

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2023 年 6 月 30 日

1 投票

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)

カテゴリ

ヘルプ センター および File ExchangeGraph and Network Algorithms についてさらに検索

製品

リリース

R2022b

質問済み:

2023 年 6 月 30 日

コメント済み:

dpb
2023 年 6 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by