Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: MathWorks <a href="http://www.mathworks.com/support/tech-notes/1100/1107.html" rel="nofollow noreferrer">give advice on this problem</a>.</p> <hr> <p>You can view memory usage with the commands <code>system_dependent memstats</code> and <code>system_dependent dumpmem</code> (as well as simply <code>memory</code>, as noted by Jonas).</p> <p>The command <code>pack</code> (which in effect defragments your workspace) may also come in useful.</p> <p>If you are dealing with objects containing > 10 million or so values, then memory can easily become an issue. Throwing hardware at the problem (i.e. buying more RAM) may be an option, but there is a limit to what you can achieve.</p> <p>The way I suggest you approach recoding things to make them more memory efficient is: </p> <p>See if there are any variables you don't need to allocate. A classic example of this is when a function returns a value of the same size as it's input.</p> <pre><code>function x = XPlus1(x) x = x + 1; end </code></pre> <p>is more memory efficient than</p> <pre><code>function y = XPlus1(x) y = x + 1; end </code></pre> <p>Next, try and split your problem down into small chunks. At the simplest level, this may involve performing an operation on rows instead of a whole matrix, or on individual elements instead of a vector. (The cost of looping is less than the cost of it not running at all due to memory contraints.) Then you have to reconstruct your answer from the pieces.</p> <p>This step is essentially the philosophy behing map-reduce, so as a bonus, your code will be more easily parallelizable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload