create sparse upper triangular matrix with only 1s
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
James Tursa
il 7 Giu 2016
Modificato: James Tursa
il 7 Giu 2016
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!