Show memory options in Matlab working on Mac platform
Show older comments
Hi all,
I am running Matlab R2012b (64 bit) on a Mac OS (version 10.8.2) computer. I am working with large arrays and like to know the memory usage by Matlab. I have tried 'memory' before on Windows platform and it always worked perfectly ... But when I typed 'memory' in the workspace, it showed the following error
" memory
Error using memory
Function MEMORY is not available on this platform. "
Can anyone help me figure out the problem... When I typed 'help memory' it displayed all information about memory function similar to any help function. Also I can see the function 'memory' in the Matlab documentation which comes along with Matlab... but when I typed 'memory' in the workspace, it showed me an error....
Any help will be greatly appreciated ...
Thanks,
Jeena
Accepted Answer
More Answers (2)
Ian
on 29 Jun 2017
Edited: Walter Roberson
on 31 Aug 2023
Several cmdline tools for determining physical memory on Macs.
I use:
[status, cmdout]=system('sysctl hw.memsize | awk ''{print $2}''')
google "MacOS sysctl" and "MacOS system_profiler for more info.
2 Comments
Mr M.
on 28 Apr 2018
Edited: Walter Roberson
on 28 Apr 2018
[status, cmdout]=system('sysctl hw.memsize | awk ''{print $2}''')
-bash: syntax error near unexpected token `('
Walter Roberson
on 28 Apr 2018
You need to execute the command inside MATLAB.
Michael Burke
on 27 Jan 2020
I created a simple function for this:
function memoryForMac()
% This function will return the memory used by MATLAB on the MAC
%
%% First get the version of MATLAB
curVer = version('-release');
%% get the PID for MATLAB
sysStr = ['ps -o ppid,command |grep ',curVer,'.app'];
[status,verStr] = system(sysStr);
if (status ~= 0)
error('MATLAB was not found: That is odd since you are in MATLAB');
end
%% Get where the string is located
% Format looks like: interested in PPID
% PPID COMMAND
% 4151 /Applications/MATLAB_R2019b.app/bin/maci64/matlab_helper /dev/ttys000 yes
slash = findstr('/',verStr);
pidStr = verStr(1:slash(1)-1);
%% Now get the memory string
sysStr = ['top -pid ',pidStr,' -l 1 -stats MEM'];
[status,info] = system(sysStr);
if (status ~= 0)
error('Invalid PID provided')
else
% now parse out the memory
memLoc = findstr(info,'MEM');
MEM = info(memLoc+5:end-1);
fprintf('Total memory used: %s\n',MEM);
end
2 Comments
Rodrigo
on 17 Jan 2023
Sir you're doing the Lord's work
Venky Kanniganti
on 26 Jan 2023
Edited: Venky Kanniganti
on 26 Jan 2023
I pray that you have spread your progeny far and wide
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!