Effacer les filtres
Effacer les filtres

how to convert edge list to adjacency matrix

5 vues (au cours des 30 derniers jours)
muhammad ismat
muhammad ismat le 18 Fév 2016
Commenté : muhammad ismat le 20 Fév 2016
i have the code
function adj=edgeL2adjj(e)
Av=[e; fliplr(e)];
nodes=unique(Av(:, 1:2)); % get all nodes, sorted
adj=zeros(numel(nodes)); % initialize adjacency matrix
% across all edges
for i=1:size(Av,1)
adj(nodes==Av(i,1),(nodes==Av(i,2)))=1;
end
end
in matlab to convert edge list to adjacency matrix but if i input u=[8 5;1 4;3 5;6 7] then i divided into two set[8 5;1 4], [3 5,6 7] and apply previous code on [8 5;1 4] will get matrix 7 x 7 but i want 8 x 8

Réponses (1)

Walter Roberson
Walter Roberson le 19 Fév 2016
u=[8 5;1 4;3 5;6 7];
num_nodes = max(u(:));
adj_matrix = accumarray(u, 1, [num_nodes, num_nodes]);
Note: if there can be duplicate entries you can add ">= 1" to the end.
  1 commentaire
muhammad ismat
muhammad ismat le 20 Fév 2016
Thanks to your efforts, it's simple code

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by