MATLAB Memory: How to Fix Memory Issues Easily

In summary, the conversation discusses a problem with memory errors when trying to plot data in MATLAB. The advice is to avoid plotting too many points at once and to clear large variables in a loop. The speaker also mentions switching to Python as an alternative to MATLAB.
  • #1
Pythagorean
Gold Member
4,401
312
I've read the (a?) MATLAB file on memory on their webiste. Basically, their advice deals with data generation, which I'm not having a problem with. I generated the data sets quite easily on my 64-bit dual core, while simultaneously posting on physicsforums and playing muds.

But once I got the graphical part, my computer kept getting swamped and memory errors kept popping up (no I'm not trying to run muds or browsers with it). Basicallly, I load and plot nine sets of data (axes) on each figure, then save it as a no compression tiff.

I do this all with the visibility off, so I'm supressing graphical output. I make sure to clear the variables before I load new ones.

I can do this once manually with no problems, but if I don't quit MATLAB and reopen it, the second manual run takes much longer and bogs my computer down (even after MATLAB has crashed and closed). I got the memory errors initially when I tried to automate the whole data set at once.
 
Physics news on Phys.org
  • #2
@Pythagorean I know that it has been a long time since you posted the thread, but do you remember how you had solved this problem?
 
  • #3
I don't for this specific case. But I remember two common gotchyas with memory in matlab.
1) don't try to plot too many points at once. Even if it's invisible.
2) make sure you're clearing big variables if you have a loop

Also, I remember Matlab was just a memory hog anyway. I've used nothing but python for the last couple years.
 
  • Like
Likes Wrichik Basu

What is MATLAB memory and why is it important?

MATLAB memory refers to the amount of space available for storing and manipulating data in the MATLAB workspace. It is important because it directly affects the performance and efficiency of MATLAB programs. If there is not enough memory available, MATLAB may run slowly or even crash.

How do I check the amount of memory available in MATLAB?

You can check the amount of memory available in MATLAB by using the "memory" function. This will display the total amount of memory, as well as how much is currently being used and how much is available for use.

What can cause memory issues in MATLAB?

There are several factors that can cause memory issues in MATLAB, including large data sets, inefficient code, and memory leaks. These issues can also be caused by using certain functions or operations that require a lot of memory, such as image processing or matrix operations.

How can I fix memory issues in MATLAB?

There are several ways to fix memory issues in MATLAB. One way is to optimize your code to use less memory, such as pre-allocating arrays and avoiding unnecessary variables. You can also increase the memory available to MATLAB by adjusting the Java Heap Memory settings. Additionally, using the "clear" function to remove unnecessary variables from the workspace can also help free up memory.

What can I do if my code is still running out of memory?

If you have optimized your code and increased the available memory, but are still experiencing memory issues, you may need to consider using a different approach to your problem. This could include breaking up your code into smaller chunks or using external memory storage, such as a hard drive or cloud storage, to store and access large datasets.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
585
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
257
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top