How to convert sparse matrix to adjacency matrix ?

2 vues (au cours des 30 derniers jours)
vignesh raju
vignesh raju le 10 Fév 2016
Commenté : the cyclist le 12 Fév 2016
How do you convert sparse matrix to adjacency matrix in Matlab 2015?
  2 commentaires
the cyclist
the cyclist le 10 Fév 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 le 11 Fév 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

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 11 Fév 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 commentaires
vignesh raju
vignesh raju le 12 Fév 2016
Modifié(e) : Walter Roberson le 12 Fév 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 le 12 Fév 2016
In MATLAB, curly brackets -- {} -- are not equivalent to parentheses -- (). Curly brackets are used for a special type of MATLAB object: a cell array.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 10 Fév 2016
adjacency_matrix = logical(TheSparseMatrix);
  2 commentaires
vignesh raju
vignesh raju le 11 Fév 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 le 11 Fév 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by