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

代码参考 | 随机网络(Matlab)
2022-01-15 19:29 Jie  RCNS

function [A,L]=buildrand(N,k)

%Builds a sparse, random network with N nodes & average degree k.  No self-connections are allowed,

%network is undirected and k must be less than N.

%Usage: [A,L]=buildrand(N,k), where L is the total number of edges (returned as a check)


L=round(N*k/2);


nett = tril(rand(N),-1); %pulls the lower tri out of rand(N)

%sortnet=sort(nett(find(nett))); %what is faster?

sortnet = sort(reshape(nett,N^2,1)); %list random values as vector

B = sparse((nett > sortnet(end-L))); %take top L values

A = B + B'; %make symmetric: zeros(N) +


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

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