Code covered by the BSD License  

Highlights from

  • whom() WHOM Lists variables in base workspace, with hypertext to clear them.
  • whoms() WHOMS Lists variables in base workspace, with hypertext to clear them.
  • View all files
image thumbnail



Matt Fig (view profile)


15 Jul 2008 (Updated )

Similar to WHO/WHOS, but allows user to click-to-clear.

function [] = whoms()
%WHOMS Lists variables in base workspace, with hypertext to clear them.
% When WHOMS displays the variable names, they are hyper-linked so that 
% clicking on a variable name in the list will clear that variable from the 
% base workspace.  WHOMS also displays information about the workspace
% variables in a manner similar to WHOS.
% WHOMS does not return a value and takes no input argument.
% Example:
%         To see what variables are in the base workspace, and gain easy
%         access to clearing them, simply type:
%         whoms
% See also clear, delete, whom.
% Author: Matt Fig
% Contact:
% 7/14/2008

% Use a very unlikely dummy variable name in the base workspace...
evalin('base','WwWwWwWw123xyz = whos;')% So as not to overwrite something.
evalin('base','assignin(''caller'',''W'',WwWwWwWw123xyz)')% Get info here.
evalin('base','clear(''WwWwWwWw123xyz'')')% clear dummy variable in base.
if isempty(W),  return,  end % No variables in the workspace.
lngth = length(W); % Used to determine cell length.
[Name{1:lngth}] = deal(; % Work with cell arrays.
mx = max(cellfun('length',Name));   % Find the maximum string length.
[Size{1:lngth}] = deal(W.size);  % Fill the headings cells.
[Bytes{1:lngth}] = deal(W.bytes);
[Class{1:lngth}] = deal(W.class);
Attributes = cell(1,lngth); % This one needs more attention because W...
    [Attsg{1:lngth}] = deal(; % doesn't have an attributes field
    [Attss{1:lngth}] = deal(W.sparse);
    [Attsc{1:lngth}] = deal(W.complex);
    Attributes(cell2mat(Attsg)) = {'global'};
    Attributes(cell2mat(Attss)) = {'sparse'};
    Attributes(cell2mat(Attsc)) = {'complex'};
     % The user has an older version of Matlab (like 6.5)
str = ['<a href="matlab:','clear(' ,'''','all','''',')','">',...
fprintf('\n%s\n',['Your variables are (click separately ',...
        'to clear or ',str,'):']) 
str = ['Name',repmat(' ',1,mx+3)]; % For the heading.
fprintf('\n  %s%s            %s  %s      %s\n\n',str,'Size','Bytes',...
ch = char(Name);  % Get a character array from the cell.
chlnk = cell(size(ch,1),1);  % Build a cell with hypertext.

for mm = 1:lngth % Build the links.
    db = deblank(ch(mm,:)); % For the html label.
    chlnk{mm} =['<a href="matlab:','clear(' ,'deblank(','''',ch(mm,:),...
                '''','))','">',db,'</a>','  '];

chlnk = char(chlnk);  % Need the padding to get display spacing correct.
for ii = 1:lngth
    Sz = [num2str(Size{ii}(1)),'x',num2str(Size{ii}(2))]; % Formatting.
    lSz = length(Sz); % Used in calculating the number of spaces needed.
    Bts = int2str(Bytes{ii}); % Same as above.
    lBts = length(Bts);
    fprintf(['  %s     %s',repmat(' ',1,21-lSz-lBts),'%s  %s     %s\n'],...
            chlnk(ii,:)',Sz,Bts,Class{ii},Attributes{ii}) % Print the lines.

fprintf('\n') % Provide a space between list and command prompt.

Contact us