Code covered by the BSD License  

Highlights from

  • figfiles(pth) FIGFILES(DIR) Lists the Matlab FIG-Files in directory DIR, with hypertext.
  • matfiles(pth) MATFILES(DIR) Lists the Matlab MAT-Files in directory DIR, with hypertext.
  • mfiles(pth) MFILES(DIR) Lists the Matlab M-Files in directory DIR, with hypertext.
  • View all files
image thumbnail



Matt Fig (view profile)


10 Jul 2008 (Updated )

Contains three functions for displaying different files with links.

function [] = figfiles(pth)
%FIGFILES(DIR) Lists the Matlab FIG-Files in directory DIR, with hypertext.
% If DIR is not specified, the current directory will be used.
% When FIGFILES displays the FIG-File names, they are hyperlinked so that 
% clicking on a filename in the list will open the figure.
% FIGFILES does not return a value.
% Examples:
%         To see what FIG-FILES are in the current directory, and gain easy
%         access to opening them, simply type:
%         figfiles
%         To see what FIG-files are in the directory on path PTH, and gain 
%         easy access to opening them, simply type:
%         figfiles(PTH)
% See also what, dir, mfiles, matfiles, whats(on the file exchange)
% Author: Matt Fig
% Contact:
% 7/8/2008

if nargin ~= 1
    pth = pwd; % User wants the the current directory.
    crnt = 'current '; % This is for display purposes later.
    crnt = '';  % For display purposes when user passed alt directory.

    W = what(pth); % W has the path name in it.
    W = W(1);
    D = dir(pth); % Use DIR to get the FIG-Files.
    fls = {}'; % Get into a cell.
    W.fig = fls(~cellfun('isempty',regexp(fls,'\.fig$'))); % FIG-Files.
    error('Invalid path, make sure the path entered is correct.')

if isempty(W.fig),  return,  end % No FIG-Files in the directory.
var = sort(W.fig); % Alphabetical order.
lngth = length(var);  % Start to calculate how many lines to display. 
mx = max(cellfun('length',var));   % 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(var);  % 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.
    db = db(1:end-4);  % Drop the extention on the label.
    chlnk{mm} =['<a href="matlab:','open' ,'(deblank(',' ''',W.path,...
                filesep,ch(mm,:),'''','))','">',db,'</a>','    '];

chlnk = char(chlnk);  % Need the padding to get display spacing correct.
fprintf('\n%s\n\n',['FIG-FILES',' in the ',crnt,'directory ', W.path,...
    '  (click to ','open','):']) % Announce what is printing.

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