Why am I unable to use linear indexing with sparse matrices when the sparse matrix is of size larger than the maximum array size in MATLAB 7.0 (R14) and later?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 27 Jun. 2009
Bearbeitet: MathWorks Support Team
am 27 Mär. 2023
I have following code:
D = sparse(756123, 769768);
i=756123;
j=769768;
D(i,j)=1;
a=D(i,j)
ind=sub2ind(size(D),i,j);
If I access the (756123, 769768)th element of "D" using linear indexing ( D(ind) ), I receive the following error:
ERROR: ??? Maximum variable size allowed by the program is exceeded.
Akzeptierte Antwort
MathWorks Support Team
am 25 Mär. 2023
Bearbeitet: MathWorks Support Team
am 27 Mär. 2023
This error is generated because of the way MATLAB 7.0 (R14) and later versions detect potential memory problems when creating and accessing elements of large sparse matrices.
When the size of the sparse matrix is larger than this limitation, MATLAB generates this error when attempting to access, using linear indexing, elements of sparse matrices that have a linear index larger than 2^31-1, disregarding the fact that the matrix is sparse.
To workaround this issue, use matrix indexing, D(i,j), to access elements of the sparse matrix with a linear index larger than 2^31-1.
See the solution below for a discussion of the limitations on the size of the largest matrix that you can create in MATLAB.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!