课程首页 | 课程简介 | 课程大纲 | 课程讲义 | 授课教师 | 网络可视化 | 课程建设动态 | 课程资讯 | 线上课程 | 头条推荐 
   
 

代码参考 | 邻接矩阵生成net文件(Matlab)
2022-01-15 19:48  

%PAJEK   Converts a Matlab weight matrix into a Pajek input file.

%   PAJEK(MAT,'file_name') writes the network described by the

%   square matrix MAT to a Pajek input file called 'file_name.net'

%   The network will be weighted and directed.

%

%   For example,

%

%      pajek(W,'Network1') eg.,

%     >> Matrix1=nearest(10,4);  

%     >> pajek(Matrix1,lj)

%

%   creates a file called 'Network1.net' in the present working

%   directory from the network descibed by W.


% Ben Skellett, 15/10/02

% Revised 28/07/03


function pajek(mat,file)


if size(mat,1)~=size(mat,2)

  error('Matrix is not square');

end


if ~ischar(file)

  error('Specify file name as a string');

end


vertices=1:size(mat,1);


[i,j,v]=find(mat);


arcs=[i'; j'; v'];


fid=fopen([file,'.net'],'w');

fprintf(fid,'*Vertices %g \r',size(mat,1));

fprintf(fid,'%g  "v%g" \r',[vertices; vertices]);

fprintf(fid,'*Arcs \r');

fprintf(fid,'%g  %g  %g\r',arcs);

fclose(fid);


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

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