title: How to Increase Java Heap Size directly in Matlab?
body: <p>I would like to increase the Java heap size directly by Matlab command because I need dynamic control depending on the environment. 
  I know the thread <a href="http://se.mathworks.com/matlabcentral/answers/92813-how-do-i-increase-the-heap-space-for-the-java-vm-in-matlab-6-0-r12-and-later-versions" rel="nofollow">How do I increase the heap space for the Java VM in MATLAB 6.0 (R12) and later versions</a> where they say to use <code>java.opts</code> file but I would like to do the same with Matlab prompt directly. 
  There are many threads that offer to change the parameters only through Matlab GUI or the file, like Matlab's blog post <a href="http://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/" rel="nofollow">Controlling the Java Heap Size</a>.</p>
  
  <p>I am interested in increasing these parameters dynamically</p>
  
  <pre><code>heapSizeMemoryDefault = 521142272; % 512 MB
  assert(java.lang.Runtime.getRuntime.maxMemory &gt; heapSizeMemoryDefault*2, 'Java heap size too small');
  runTimeMemoryDefault = 90116624; % about 890 MB
  assert(java.lang.Runtime.getRuntime.freeMemory &gt; 90116624*2, 'Java free memory size too small');
  </code></pre>
  
  <hr>
  
  <p>How can you increase Java heap size directly in Matlab 2016a?</p>