非线性科学研究中心
 
Home | News | Research | People | Publications | Courses | NetworkScience | Conference | Workshop | Links | Softwares
   
 

 

FYI: Useful toolkit of convert matrix to net files.

2018年04月16日 10:10 Jie 点击:[]

function writetoPAJ(CIJ, fname, arcs)

% writes a Pajek .net files from a MATLAB matrix
% CIJ = adjacency matrix
% fname = filename minus .net extension
% arcs = 1 produces a directed net, arcs = 0 an undirected net

N = size(CIJ,1);
fid = fopen(cat(2,fname,'.net'), 'w');

%%%VERTICES
fprintf(fid, '*vertices %6i \r', N);
for i = 1:N
   fprintf(fid, '%6i "%6i" \r', [i i]);
end

%%%ARCS/EDGES
if arcs
   fprintf(fid, '*arcs \r');
else
   fprintf(fid, '*edges \r');
end

for i = 1:N
   for j = 1:N
       if CIJ(i,j) ~= 0
           fprintf(fid, '%6i %6i %6f \r', [i j CIJ(i,j)]);
       end
   end
end

fclose(fid)

 

上一条:FYI: Running R Scripts From Matlab

关闭

  读取内容中,请等待...

版权所有:Research Centre of Nonlinear Science 邮政编码:430073
E-mail:liujie@wtu.edu.cn 备案序号: 鄂ICP备15000386号 鄂公网安备 42011102000704号