フィルターのクリア

Convert Adjacency list of graph into Adjacency matrix

4 ビュー (過去 30 日間)
POLLY
POLLY 2018 年 10 月 17 日
回答済み: Guillaume 2018 年 10 月 17 日
I am working with Adjacency lists of a graph with 198 vertices and 2472 edges. How can I construct adjacency matrix of graph in Matlab?
Thank you for any help
  1 件のコメント
Guillaume
Guillaume 2018 年 10 月 17 日
What form do the lists come in?

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

回答 (3 件)

Bruno Luong
Bruno Luong 2018 年 10 月 17 日
use SPARSE or ACCUMARRAY

Steven Lord
Steven Lord 2018 年 10 月 17 日
How is your data stored?
Do you have a matrix or two vectors containing the endpoints of the edges? In this case you can use sparse or accumarray as Bruno suggested.
Do you have a graph or digraph object? Call adjacency on it.
Is your data stored in a different way? If so, describe your storage system and we may be able to offer some guidance.
  1 件のコメント
POLLY
POLLY 2018 年 10 月 17 日
編集済み: POLLY 2018 年 10 月 17 日
My data is given in this file. We use the popular Metis input/output format. I have attached an example for Metis input

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


Guillaume
Guillaume 2018 年 10 月 17 日
One possible way to read your file:
lists = strsplit(fileread('list.txt'), {'\r', '\n'});
if isempty(lists{end}), lists = lists(1:end-1); end
lists = cellfun(@(v) sscanf(v, '%d'), lists, 'UniformOutput', false);
adj = sparse(repelem(1:numel(lists), cellfun('length', lists)), vertcat(lists{:}), 1)
If you want a full matrix:
full(adj)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by