create sparse upper triangular matrix with only 1s

4 ビュー (過去 30 日間)
freebil
freebil 2016 年 6 月 7 日
編集済み: James Tursa 2016 年 6 月 7 日
Hello. I want to create a sparse upper triangular with size 10^5x10^5. Is it possible?
m = triu(ones(10^5);
and
m = sparse(triu(ones(10^5));
exceed maximum array size preference. Thanks.

採用された回答

James Tursa
James Tursa 2016 年 6 月 7 日
編集済み: James Tursa 2016 年 6 月 7 日
A sparse version of the full triangular matrix will have slightly over 1/2 of the values, plus some extra overhead for the explicit index numbers that are saved. A comparison of memory usage is:
n = number of rows & columns
full memory = 8*n^2 bytes
sparse memory = (8 + (4 or 8))*n*(n+1)/2 + (4 or 8)*(n+1) bytes
The (4 or 8) will depend on whether the indexing is saved as 4 or 8 byte integers on your machine.
So, if we assume 8 byte integers on your machine and n = 10^5, the memory comparison is:
full memory = 8e10 bytes
sparse memory = 8.0001600008e+10 bytes
The sparse version of this triangular matrix will actually consume more data memory than the full version.
A logical version of this matrix will consume this amount of data memory:
sparse logical memory = (1 + (4 or 8))*n*(n+1)/2 + (4 or 8)*(n+1) bytes
So for 8 byte indexing and n = 10^5 as above, you would get:
sparse logical memory = 4.5001250008e+10 bytes
Still 56% the size of the full double version, so probably not what you need.
You need to find another way to solve your problem.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by