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.
Asked
Active
Viewed 4,462 times
3
2 Answers
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
-
2Thanks 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