# Largest lindexing supported by MATLAB?

1 view (last 30 days)
Bruno Luong on 9 Dec 2022
Edited: Bruno Luong on 9 Dec 2022
What is the largest (linear) indexing supported by MATLAB? I would be good to know if there is an official specification for such thing.
Stephen23 on 9 Dec 2022
Edited: Stephen23 on 9 Dec 2022
"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.

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 CommentsShowHide 1 older comment
Bruno Luong on 9 Dec 2022
Edited: Bruno Luong on 9 Dec 2022
Thanks Rik
[~,maxsize] = computer
is the way to go.

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!