将GML文件转换为matlab中的邻接矩阵 [英] Convert GML file to adjacency matrix in matlab
本文介绍了将GML文件转换为matlab中的邻接矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 GML 文件的有向图(政治博客)。我想在Matlab中使用这个图作为一个邻接矩阵。我如何转换它?
Thanks。
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.
推荐答案
有一个示例代码 here
用于此目的:
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 []
,一个
[mx 2]
矩阵,包含节点之间的链接。
A[]
, an [m x 2]
matrix, contains the links between nodes.
这篇关于将GML文件转换为matlab中的邻接矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文