Code covered by the BSD License  

Highlights from
mfiles/matfiles/figfiles

  • 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

mfiles/matfiles/figfiles

by

 

10 Jul 2008 (Updated )

Contains three functions for displaying different files with links.

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

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

try
    W = what(pth);  % Use WHAT to get the files we want.
    W = W(1);
catch
    error('Invalid path, make sure the path entered is correct.')
end

if isempty(W.mat),  return,  end % No MAT-Files in the directory.
var = sort(W.mat);  % 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:','load' ,'(deblank(',' ''',W.path,...
                 filesep,ch(mm,:),'''','))','">',db,'</a>','    '];
end

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

for ii = 1:nmlns
    fprintf('%s\n',chlnk(ii:nmlns:lngth,:)') % Print the lines.
end
    
fprintf('\n') % Provide a space between list and command prompt.

Contact us