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
Teja Muppirala 2011 年 5 月 13 日

0 投票

If "A" is your sparse matrix, then:
A(find(A)) = randi(maxweight,nnz(A),1);
will replace every element with a random integer.

1 件のコメント

Mehmet Candemir
Mehmet Candemir 2011 年 5 月 13 日
Thanks that was really fast

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

製品

質問済み:

2011 年 5 月 13 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by