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?

3 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Mar 2023
Edited: MathWorks Support Team on 27 Mar 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.

More Answers (0)

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!