Largest lindexing supported by MATLAB?

What is the largest (linear) indexing supported by MATLAB? I would be good to know if there is an official specification for such thing.

4 Comments

Hi, I'd like to know the same for in-memory arrays, but for tall arrays, it seems there's no limit at all: " tall arrays can be arbitrarily large in the first dimension (that is, they can have any number of rows)." (see here)
I seem to recall a post (probably by Walter) that indices are limited to 32 bit integers, but I only remember seeing explicit statements in the documentation itself for mat files.
Should be easy enough to find by trial and error, but I'm on mobile, so I can't use the editor to do so.
After some search and testing, it seems that information provided by the function intmax gives the answer for integers.
"it seems that information provided by the function intmax gives the answer for integers. "
How? I don't see anything on that page related to maximum index size (only the unrelated max value). Using the same test that Rik proposed gives exactly the same error message as the default DOUBLE():
A = uint8(0);
A(flintmax) = 1;
One or more indices are invalid. Indices must be less than 2^48.

Sign in to comment.

 Accepted Answer

Rik
Rik on 9 Dec 2022
Edited: Rik on 9 Dec 2022
For a double, you can just look at the error message:
try
A=[];
A(flintmax)=1;
catch ME,disp(ME.message),end
One or more indices are invalid. Indices must be less than 2^48.
And if I test for an integer type, it seems that same limit applies, at least on the 64 bit Linux version that the forum uses.
try
A=uint8([]);
A(intmax+1)=1;
catch ME,disp(ME.message),end
try
A=uint8([]);
A(flintmax)=1;
catch ME,disp(ME.message),end
One or more indices are invalid. Indices must be less than 2^48.
After your comment I wanted to see what would happen when trying to create an array beyond the allowed index range, which gave me this error message:
try
S=sparse(2^49,2)
catch ME,disp(ME.message),end
Sparse matrix sizes must be nonnegative integer scalars less than MAXSIZE as defined by COMPUTER. Use HELP COMPUTER for more details.
So apparently we need the computer function:
[str,maxsize] = computer; log2(maxsize) % this is a rounding error, maxsize is 2^48-1
ans = 48.0000
On 32 bit Matlab releases this seems to be 2^31-1.

2 Comments

Also for sparse but the message is not clear
S=sparse(2^25,2^25)
S =
All zero sparse: 33554432×33554432
S(end,end)
ans =
All zero sparse: 1×1
S(end) % "end" is equivalent to 2^50
Requested array exceeds the maximum possible variable size.
Thanks Rik
[~,maxsize] = computer
is the way to go.

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Asked:

on 9 Dec 2022

Edited:

on 9 Dec 2022

Community Treasure Hunt

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

Start Hunting!