Skip to content

Instantly share code, notes, and snippets.

@import-benjamin
Created November 25, 2017 14:28
Show Gist options
  • Save import-benjamin/8679a220a2091292c5fddbed044b9c17 to your computer and use it in GitHub Desktop.
Save import-benjamin/8679a220a2091292c5fddbed044b9c17 to your computer and use it in GitHub Desktop.
graph theory : convert adjacency matrix to adjacency list in scilab
// desc : retourne une matrice sous forme de liste d'adjacence
// input : matrice d'adjacence (M)
// ouput : Liste d'adjacence ([S, T])
function [S, T] = mat2listes(M)
tailleMatrice = size(M,1)
S = [] // liste des successeurs.
T = [1] // initialise forcément à 1.
for k=1:tailleMatrice
S = [S, find(M(k,:) == 1)] // on récupère les numéros lignes qui sont à 1
T = [T, length(S)+1] // on indique le début du prochain sommet
end
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment