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




15 Jul 2008 (Updated )

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

function [] = whom()
%WHOM Lists variables in base workspace, with hypertext to clear them.
% When WHOM 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.
% WHOM 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:
%         whom
% See also clear, delete, whoms.
% Author: Matt Fig
% Contact:
% 7/14/2008

% Use a very unlikely dummy variable name in the base workspace...
evalin('base','WwWwWwWw123xyz = who;')% 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);  % Start to calculate how many lines to display. 
mx = max(cellfun('length',W));   % Find the maximum string length.
cwsz = get(0,'commandwindowsize'); % Find out how many will fit.
vct = 1:75;  %  Try several different numbers to find how many lines.
vct = floor(cwsz(1)./(vct*mx + (vct-1)*3));  % ~3 spaces between strings.
nmprln = find(vct==1);  % Last index is the num per line, see next comment.
nmprln = nmprln(end); % For BC to ver 6.5: no 'last' arg to find func. :(
if isempty(nmprln),  nmprln=1;  end  % User has very small command window! 
nmlns = ceil(lngth/nmprln); % This is how many lines to display.
ch = char(W);  % Get a character array from the cell.
chlnk = cell(size(ch,1),1);  % Build a cell with hypertext.

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

str = ['<a href="matlab:','clear(' ,'''','all','''',')','">',...
fprintf('\n%s\n\n',['Your variables are (click separately ',...
        'to clear or ',str,'):']) 
chlnk = char(chlnk);  % Need the padding to get display spacing correct.

for ii = 1:nmlns
    fprintf('%s\n',chlnk(ii:nmlns:lngth,:)') % Print the lines.

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

Contact us