Replacing 1s in a sparse matrix by a random int.
이전 댓글 표시
Hi everyone I have a adjacency matrix from which I want to create a weight matrix. For each nonzero entry I'll put a random number in the weight matrix. The reason I want to this way is to reduce memory requirements. for instance if n=100'000. I create a sparse binary adjacency matrix with no problem. If I create my Weight matrix by W=randi(maxweight,n,n) it will consume a lot memory. Instead, i want it to be sparse as the adjacency matrix.
답변 (1개)
Teja Muppirala
2011년 5월 13일
If "A" is your sparse matrix, then:
A(find(A)) = randi(maxweight,nnz(A),1);
will replace every element with a random integer.
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!