Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 生成稀疏行随机矩阵?_Matlab_Matrix_Sparse Matrix_Stochastic - Fatal编程技术网

Matlab 生成稀疏行随机矩阵?

Matlab 生成稀疏行随机矩阵?,matlab,matrix,sparse-matrix,stochastic,Matlab,Matrix,Sparse Matrix,Stochastic,我试图用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); 最后一行就是它失败的地方。稀疏矩阵中有一些零行 因此,我的问题是如何规范化每一行,同时保留零行?这是我将

我试图用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); 
最后一行就是它失败的地方。稀疏矩阵中有一些零行


因此,我的问题是如何规范化每一行,同时保留零行?

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

%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);
%逻辑矩阵,一个网页平均链接到20%的其他网站。这是一个奇怪的模型,但我没有更好的想法:

doeslink=rand(N)行
S1=sparse(i,j,1,N,N)也会导致错误。max(i)和max(j)在某些情况下是11,这超过了NxN的大小。谢谢。我会投票支持你的答案,但我太新了。你可以点击复选标记。这表明您已经找到了解决方案,这不再是一个悬而未决的问题。