Skip to content

Instantly share code, notes, and snippets.

@amar-b
amar-b / graphML2Matrix.m
Last active February 17, 2020 00:35
Matlab script to convert GraphML files to adjacency matrices
function A = graphML2Matrix(path)
% Reads a graphml file and represents graph as adjanency matrix
xml = xmlread(path);
graph = xml.getElementsByTagName('graph');
idMap = containers.Map('KeyType','char','ValueType','uint64');
if (graph.getLength == 1)
V = graph.item(0).getElementsByTagName('node');
n = V.getLength;
A = zeros(n,n);
for i = 1:n