i want to create a square array of 1048560x1048560 but i am getting an Error using zeros Requested 1048560x1048560 (8191.8GB) array exceeds maximum array size preference.

1 次查看(过去 30 天)
Error using zeros
Requested 1048560x1048560 (8191.8GB) array exceeds maximum array size preference. Creation of arrays greater than this
limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more
information.
  2 个评论
Rik
Rik 2022-4-20
It is not just that you need 8TB of free RAM, it also needs to be contiguous. Maybe a sparse array will do what you need, but you might have to rethink your strategy.

请先登录,再进行评论。

回答(2 个)

Steven Lord
Steven Lord 2023-9-28
@Simar wrote, in part:
By default, MATLAB has a maximum array size limit to prevent excessive memory usage and potential system instability.
This part is true.
In this case, it exceeds the default maximum array size limit.
This part is not true. It does not exceed the maximum array size limit. If it had you would have seen a different error message:
try
x = ones(1e8);
catch ME
fprintf("This command threw error:\n%s", ME.message)
end
This command threw error: Requested array exceeds the maximum possible variable size.
I believe the "MATLAB array size limit" preference in the Workspace section of the preferences for MATLAB on the preferences page is enabled by default. This doesn't set the theoretical maximum upper limit (that is unchangeable as long as you're on a 64-bit system; if you went back to a 32-bit version of MATLAB in release R2015b or earlier that maximum limit would be much smaller) but what percentage of the RAM on your machine you want to allow MATLAB to try to use for one array. You can tell MATLAB not to be limited by that percentage, but if you try to create an array larger than your system's RAM it might take a very, very long time trying to create that array.
In this particular case, depending on how sparsely populated the original poster needs their matrix to be, creating a sparse matrix may satisfy their needs.
n = 1048560;
s1 = sparse(n, n) % no non-zero elements
s1 =
All zero sparse: 1048560×1048560
s2 = spalloc(n, n, 10*n) % average of 10 non-zero elements per row
s2 =
All zero sparse: 1048560×1048560
whos s1 s2
Name Size Bytes Class Attributes s1 1048560x1048560 8388504 double sparse s2 1048560x1048560 176158088 double sparse
s1 has essentially no room allocated for elements, while s2 is "ready to accept" 10*n non-zero elements.
nzmax(s1)
ans = 1
nzmax(s2)
ans = 10485600

Simar
Simar 2023-9-28
I understand that MATLAB is trying to create an array of size 1048560 x 1048560, which requires approximately 8191.8GB of memory. By default, MATLAB has a maximum array size limit to prevent excessive memory usage and potential system instability. In this case, it exceeds the default maximum array size limit.
Please try the following to avoid maximum array size overflow issue:
  1. Reduce the size of the array, by working with smaller subsets of the data.
  2. Use alternative data structures or files if the array size is too large to fit into memory, consider using data structures like sparse matrices or storing the data on disk and accessing it using file input/output operations as needed.
You could also refer to the documentation link for more information-
Best Regards,
Simar

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by