create sparse upper triangular matrix with only 1s

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by