How can I let MATLAB use all physical memory from my system?

3 views (last 30 days)
I observe "out of memory" issues when running certain commands in MATLAB.
For example, if I run
>> A = rand(1e5);
I get:
Error using rand Requested 100000x100000 (74.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive.
Looking at the "memory" command i get the following output:
>> memory Maximum possible array: 3434 MB (3.600e+09 bytes) * Memory available for all arrays: 3434 MB (3.600e+09 bytes) * Memory used by MATLAB: 1129 MB (1.184e+09 bytes) Physical Memory (RAM): 16158 MB (1.694e+10 bytes) * Limited by System Memory (physical + swap file) available.
How can I get MATLAB to use all available memory from the system so that I do not run into Out of Memory Issues?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Jan 2025
Edited: MathWorks Support Team on 31 Jan 2025
In order to do this, you can increase the System Swap Space. To learn how this can be done, execute the following command in the MATLAB R2020b command window to access the relevant documentation:
>> web(fullfile(docroot, 'matlab/matlab_prog/resolving-out-of-memory-errors.html'))
Additionally, you can adopt coding strategies for efficient use of memory. For more information on these strategies, run the following command in MATLAB R2020b:
>> web(fullfile(docroot, 'matlab/matlab_prog/strategies-for-efficient-use-of-memory.html'))
Please follow the link below to search for the required information regarding the current release:

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!