|
"Matt J "
> function mem=meg(varargin)
> %
> %Issuing the command MEG returns the number of megabytes of used memory
> %as tracked by WHOS().
> %
> %MEG X Y will display the memory in MB consumed (according to whos) by variables X %and Y
another, slightly more versatile approach...
- note the enhanced possibility to input a var
%SYNTAX
%---------------------------------
% MEB x y* 'zz';
% MEB('x',zzz,'y*');
%
function r=meb(varargin)
mb=2^20;
in='';
if nargin
arg=varargin;
ix=~cellfun(@ischar,arg);
in=arrayfun(@inputname,find(ix),'uni',false);
arg(ix)=in;
arg=unique(arg);
in=sprintf('''%s'',',arg{:});
in(end)='';
end
% get/convert var name/size
com=['whos(',in,');'];
s=evalin('base',com);
sn={s.name}.';
sb=cat(1,s.bytes)./mb;
r=[sn,num2cell(sb)].';
% beautify output
tl=1+max(cellfun('length',sn));
bl=1+max(ceil(log10(sb)));
fm=sprintf('%%-%ds %%%d.2f MB\n',tl,bl);
r=sprintf(fm,r{:});
disp(r);
if ~nargout
clear r;
end
end
but: this is probably NOT what the OP is looking for...
us
|