What is the largest number of rows of a matrix that Matlab can handle?
18 views (last 30 days)
Show older comments
What is the largest number of rows of a matrix that Matlab can handle? How can one know that limit in my PC?
4 Comments
Accepted Answer
More Answers (1)
Steven Lord
on 29 Jul 2020
The theoretical limit is the number returned as the second output of the computer function.
The practical limit is based on how much memory you have on your system, as it's highly unlikely you have a machine capable of creating a matrix large enough to approach the theoretical limit (unless it's a sparse tall but thin matrix.)
>> x = sparse(2^48-1, 1, 1)
x =
(281474976710655,1) 1
>> x = sparse(2^48, 1, 1)
Error using sparse
Index into matrix is too large.
In 32-bit releases of MATLAB, it was much easier to reach the theoretical limit.
3 Comments
Steven Lord
on 29 Jul 2020
>> [comptype, maxsize] = computer
comptype =
'PCWIN64'
maxsize =
281474976710655
The sparse x I created has exactly maxsize rows.
If you tried to create an array with an extremely large number of dimensions then yes, you'd consume a lot of memory with the size vector. In this example z only has two elements but it takes a little while to create.
x = [ones(1, 1e8), 2];
z = ones(x);
whos z
Bruno Luong
on 29 Jul 2020
Edited: Bruno Luong
on 29 Jul 2020
That's interesting. I believe some older MATLAB release the limits is about 2^32 (not a lot) even for 64-bits PC. Not sure if it's a limits of conception or internal overflow bug. Glad to see TMW push this boundary further away. I might revisit my test to see if the issue I found earlier is indeed solved.
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!