MATLAB: 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

indexinglinearMATLABmatrixmaximumsize;sparsevariable

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:
??? Maximum variable size allowed by the program is exceeded.

Best Answer

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.