How to convert sparse matrix to adjacency matrix ?

2 views (last 30 days)
How do you convert sparse matrix to adjacency matrix in Matlab 2015?
  2 Comments
the cyclist
the cyclist on 10 Feb 2016
I don't understand completely. A sparse matrix could be an adjacency matrix.
Can you please give a small example or two of the input/output you expect?
vignesh raju
vignesh raju on 11 Feb 2016
Sure. I'm trying to convert a .gml file to adjacency matrix, while doing so i converted the .gml file to sparse matrix and was wondering how to convert that to adjacency matrix. Is there a better way to solve this? Sorry I'm new to matlab

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 11 Feb 2016
This submission on the MATLAB File Exchange says that it will convert a *.gml file to an adjacency matrix. Maybe it will work for you.
  6 Comments
vignesh raju
vignesh raju on 12 Feb 2016
Edited: Walter Roberson on 12 Feb 2016
This code converts adjacency list to adjacency matrix and it had {} brackets before i changed them to ()
%function adj=adjL2adj(adjL)
adj1 = zeros(length(A));
for i=1:length(A)
for j=1:length(A{i});
adj1(i,A{i}(j))=1;
end
end
the cyclist
the cyclist on 12 Feb 2016
In MATLAB, curly brackets -- {} -- are not equivalent to parentheses -- (). Curly brackets are used for a special type of MATLAB object: a cell array.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 10 Feb 2016
adjacency_matrix = logical(TheSparseMatrix);
  2 Comments
vignesh raju
vignesh raju on 11 Feb 2016
It becomes a sparse logical matrix. An adjacency matrix is a square matrix and I'm unable to get that as output.
Walter Roberson
Walter Roberson on 11 Feb 2016
s = size(adjacency_matrix);
if s(1) < s(2)
adjacency_matrix(s(2),s(2)) = 0;
elseif s(1) > s(2)
adjacency_matrix(s(1),s(1)) = 0;
end

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!