Largest lindexing supported by MATLAB?
1 view (last 30 days)
Show older comments
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
Jiri Hajek
on 9 Dec 2022
After some search and testing, it seems that information provided by the function intmax gives the answer for integers.
Accepted Answer
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
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
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
So apparently we need the computer function:
[str,maxsize] = computer; log2(maxsize) % this is a rounding error, maxsize is 2^48-1
On 32 bit Matlab releases this seems to be 2^31-1.
2 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!