0

我正在尝试使用 Matlab 生成一个稀疏随机矩阵,但目前遇到了问题。这是我目前所在的位置。

N=10
i = round(rand(1,N)*10)+1 
j = round(rand(1,N)*10)+1

S1 = sparse (i,j,1,N,N);
S = full(S1)

rowsum = sum(S,2); 
S = bsxfun(@rdivide, S, rowsum); 

现在这最后一行是它失败的地方。稀疏矩阵中有一些零行。

所以我的问题是如何标准化每一行但保留零行?

4

1 回答 1

1

这是我将使用的一个非常简单的模型:

%logical matrix, a web page links to 20% of the other websites on average. This is a strange model, but I don't have a better idear:
doeslink=rand(N)<.2.*1-eye(N)
%generate random link weights
S=rand(N).*doeslink
%avoid nans
rowsum(rowsum==0)=1
%normalise
S = bsxfun(@rdivide, S, rowsum);
于 2014-02-08T23:24:20.323 回答