I’ve got a copy of Matlab from 2004 (forgot what the version number would be, but it certainly is old), and I could use the “features memstat” command to see how much memory is available to Matlab. The command no longer works for me in Matlab 2010b, what should I do to see available memory? Thanks.
P.S. I tried the “memory” command as suggested by @Rasman but got the following error:
??? Error using ==> memory Function
MEMORY is not available on this
platform.
I am running Matlab 2010b for Mac OS X 64-bit.
Use
unix('vm_stat');in MATLAB on a Mac. This gives, for example:Results are in pages of 4096 bytes, so multiply results by 4096 and you get values consistent with Activity Monitor (you have to add ‘speculative’ to ‘free’ to get exact agreement). If you just want the available memory, you can use
unix('vm_stat | grep free');. If you want a number you could use something like:EDIT: in response to a comment below “It doesn’t tell you how much MATLAB used up and how much more MATLAB can use.” Here is what I do for that additional question.
From my experience, 64 bit MATLAB can use up all of the free memory (and more but it slows down a lot if you start swapping much). One of my systems has 22Gb and it has no trouble using all of that. If you’re using 32 bit MATLAB you’re limited to 2Gb.
To see the total memory, you can add up ‘free’+’active’+inactive’+’speculative’+’wired’ from
vm_stat(and multiply by 4096). Or, if you just want the total memory, you can useunix('sysctl hw.memsize | cut -d: -f2')(in bytes).To get the memory used by MATLAB, is slightly more involved. The memory is used by the controlling process. If you just use
unix('ps'), you’ll get the memory used bymatlab_helper. So I use:Above I’ve used a little
awkfunction which picks off a named column:A little tutorial of the
unixcommand to explain the above, in case it helps anyone.unix('command')on its own shows you the output and returns the status. If you want to process the output, use[s,w] = unix('command')and deal with the string output inw. If you want to ignore thesoutput, in later versions of MATLAB, you can use[~,w] = unix('command'), but I avoid that since I inevitably have different versions on different computers.