Is this an Adjacency list ?

1 view (last 30 days)
vignesh raju
vignesh raju on 13 Feb 2016
Commented: Walter Roberson on 21 Feb 2016
I converted a .gml file to adjacency list and got the following output. Is this how an adjacency list of 7x1 cell look?
li =
[1x2 double]
[1x2 double]
[1x2 double]
[1x2 double]
[1x2 double]
[1x2 double]
[1x2 double]

Accepted Answer

Walter Roberson
Walter Roberson on 13 Feb 2016
It could. But it probably doesn't.
You could use cell2mat(li) which would output a 7 x 2 numeric array.
I suspect that our li is a list of node number pairs, as opposed to an adjacency matrix. If so then,
li_m = mat2cell(li);
numnodes = max(li_m(:));
adj = sparse(li_m(:,1), li_m(:,2), 1, numnodes, numnodes);
  3 Comments
vignesh raju
vignesh raju on 21 Feb 2016
Solved that by using it directly as an array and not as a cell array.
Walter Roberson
Walter Roberson on 21 Feb 2016
Sorry,
li_m = mat2cell(li);
should have been
li_m = cell2mat(li);

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!