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 个)
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
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
s2 = spalloc(n, n, 10*n) % average of 10 non-zero elements per row
whos s1 s2
s1 has essentially no room allocated for elements, while s2 is "ready to accept" 10*n non-zero elements.
nzmax(s1)
nzmax(s2)
0 个评论
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:
- Reduce the size of the array, by working with smaller subsets of the data.
- 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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!