How do I graph an adjacency list?

31 ビュー (過去 30 日間)
RevengeOfTee
RevengeOfTee 2020 年 2 月 16 日
コメント済み: matlabpasta 2020 年 2 月 17 日
Hello everyone.
I have a graph being respresented as an Adjacency list:
AdjTable{1} = [2];
AdjTable{2} = [1, 3, 4];
AdjTable{3} = [2, 5];
AdjTable{4} = [2];
AdjTable{5} = [3];
G = AdjTable;
I was wondering how I can visually show this on a plot. I understand you're able to do this with Adjacency matrixers but can I stick to only using the lists?

採用された回答

Walter Roberson
Walter Roberson 2020 年 2 月 16 日
Easiest way is to convert the adjacency list into an adjacency matrix. For each entry, set the matrix true at the row number corresponding to the cell index, and the column numbers given inside the entries. Then you can use graph() or digraph() and plot() the graph or digraph object.
(It can all be done in one line, but that is advanced MATLAB. Using sparse arrays helps.)
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 2 月 17 日
adj(rowidx, AdjTable{rowidx}) =1;
matlabpasta
matlabpasta 2020 年 2 月 17 日
I am attempting to solve this problem and the line works properly by outputting a 4D double like so: adj(:,:,1,1), adj(:,:,2,1) ... adj(:,:5,2). It works but I am trying to get all the true results to output into a single array rather than 10 different arrays(for this specific example). I am not sure if what I said makes sense but I have posted the code I used below.
AT is the adjacency table and G1 == adj
ss = size(AT);
for ii = 1:ss(2)
rowidx = AT{ii};
G1(rowidx, AT{rowidx}) = 1;
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by