3

I have a GML file of a directed graph (Political blogs). I want to use this graph in Matlab as an adjacency matrix. How can I convert it? Thanks.

John Powell
  • 12,253
  • 6
  • 59
  • 67
Fatime
  • 197
  • 1
  • 5
  • 15

2 Answers2

1

There is a sample code here for this purpose:

%Extracting edges from gml file graph
fileName = 'dolphins.gml';
inputfile = fopen(fileName);
A=[];
l=0;
k=1;
while 1
      % Get a line from the input file
      tline = fgetl(inputfile);
      % Quit if end of file
      if ~ischar(tline)
          break
      end
      nums = regexp(tline,'\d+','match');
      if length(nums)
          if l==1
              l=0;
              A(k,2)=str2num(nums{1});  
              k=k+1;
              continue;
          end
          A(k,1)=str2num(nums{1});
          l=1;
      else
          l=0;
          continue;
      end
end

A[], an [m x 2] matrix, contains the links between nodes.

Sam R.
  • 16,027
  • 12
  • 69
  • 122
  • Thanks to answer to newcomer :) .I check the code it seems to work.But Online converter loading till now and I don't see the result in it!!! – Fatime Apr 10 '13 at 08:44
  • @Fatime, you're right. I tried the online converter myself and it stuck at something. But I think it's better to parse your graph inside MATLAB rather than relying on an online one. – Sam R. Apr 10 '13 at 08:46
  • 2
    Thanks again,I wanted to check it and compare the result because the number of edges was different from the result of gephi graph software but I think there are some parallel links(https://gephi.org/) The Matlab code works. – Fatime Apr 10 '13 at 09:00
0

With R you can use:

library("multiplex") ## >v1.5 
read.gml(file, as="matrix")
JARO
  • 249
  • 2
  • 12