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 Ansicht (letzte 30 Tage)
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 Kommentare
KSSV
KSSV am 20 Apr. 2022
Why you want to create such a big zeros matrix? Your RAM has to support for that. Check memory.
Rik
Rik am 20 Apr. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Steven Lord
Steven Lord am 28 Sep. 2023
@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 am 28 Sep. 2023
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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by