MATLAB Answers


How to increase the memory that MATLAB uses?

Asked by April Bryan on 18 May 2018
Latest activity Answered by April Bryan on 21 May 2018

I have 19 GB of memory available for running Matlab. However, Matlab is only using 1 GB of memory. This is adversely affecting my ability to run my code. How do I increase the amount of memory that Matlab is using?


Sign in to comment.





4 Answers

Answer by OCDER
on 18 May 2018
Edited by Walter Roberson
on 18 May 2018
 Accepted Answer

This was answered here:

Matlab will use more memory if you need more memory. It's not capped at 1 GB. To test this, try:

>> memory
>> a = rand(20000);
>> memory

You'll notice that the memory usage by Matlab increases

Is there an error like "Out of Memory"? If yes, then it's indeed a memory issue that needs to be fixed by changing the way your code loads large data. If not, then it's not a memory issue but slow algorithm issue. These articles can help:

To help you determine the code bottleneck, use the profile:


Sign in to comment.

Answer by April Bryan on 18 May 2018


Thank you for your response. I did not have an out-of-memory issue. Also, I tried to use as much good programming practice as I can.

When I used the code you suggested, I received an increase in memory. However, when I close Matlab, the increase disappears and it is necessary for me to re-run the code again. Is there a way to obtain a permanent increase in memory?



When you say "permanent increase in memory" do you mean an increase in the amount of memory MATLAB is using (which is easy) or do you mean an increase in the amount of memory available to MATLAB (which may not be so easy.)

Which release of MATLAB are you using?

Are you using a 32-bit or 64-bit version of MATLAB?

If you are not getting "out of memory", then what adverse impact are you seeing on your code?

Are you running on a system that is being used for other memory-intensive purposes as well, and you want to somehow "reserve" memory for MATLAB so that it does not have to dynamically compete with the other programs that are asking for a lot of memory?

Sign in to comment.

Answer by April Bryan on 21 May 2018

I meant an increase in the amount of memory available to Matlab. The memory >> rand >> memory series of commands, allows me to gain a temporary increase in the amount of memory that Matlab is using. However, I have to reset it every time I open Matlab for the first time.

Prior to using the memory >> rand >> memory series of commands, Matlab would only use 34 % of my available memory. When I opened other programs, then my memory usage increased. I am not sure what was capping the availability of memory. The series of memory commands allowed for the usage of up to 85 % of available memory by Matlab. However, as mentioned, I have to re-run the commands, every time I open Matlab.

The cap in the availability of memory was causing my program to run slowly. When the cap was released, I saw a 10 time improvement in performance.

  1 Comment

The memory >> rand >> memory command is only there to show you that Matlab changes it's memory usage dynamically, depending how much memory you need. And how are you removing the memory cap? Is doing a = rand(20000) making your code faster? That is indeed odd, as a = rand(20000) decreases your available memory...

Sometimes the initialization of Matlab is slow, and running a script the first time is slow. Is it still slow when you rerun the same script? Maybe this Q&A is relevant:

Have you tried the profile function to see what is causing your program to run slowly?

%Try this example, directly from "help profile" command
profile on       %Begin tracking code performance
plot(magic(35))  %Replace this line with your code summon that's slow
profile viewer   %View time to run each line of code. Which one is slow? 

Try the profiler first and locate the lines of code that are taking a long time. Without this info and code, it's hard to debug.

Last, use the Comments section instead of the Answer section to respond.

Sign in to comment.

Answer by April Bryan on 21 May 2018

Thanks. That worked great! I was able to find the bottlenecks in the code with the profile command.


Sign in to comment.