Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slchangefilepart
Home > sltoolbox > fileio > slchangefilepart.m

slchangefilepart

PURPOSE ^

SLCHANGEFILEPART Changes some parts of the file path

SYNOPSIS ^

function newfp = slchangefilepart(fp, varargin)

DESCRIPTION ^

SLCHANGEFILEPART Changes some parts of the file path

 $ Syntax $
   - newfp = slchangefilepart(fp, partname1, part1, ...)

 $ Description $
   - newfp = slchangefilepart(fp, partname1, part1, ...) changes the 
     specified part of a path to a new value to form a new path.
     Please refer to slfilepart for part names

 $ Remarks $
   - If you specify the name, then you should be specify title and ext.

 $ History $
   - Created by Dahua Lin, on Aug 12nd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
  • edl_readexpdefs EDL_READEXPDEFS Reads in an experiment definition from XML file

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function newfp = slchangefilepart(fp, varargin)
0002 %SLCHANGEFILEPART Changes some parts of the file path
0003 %
0004 % $ Syntax $
0005 %   - newfp = slchangefilepart(fp, partname1, part1, ...)
0006 %
0007 % $ Description $
0008 %   - newfp = slchangefilepart(fp, partname1, part1, ...) changes the
0009 %     specified part of a path to a new value to form a new path.
0010 %     Please refer to slfilepart for part names
0011 %
0012 % $ Remarks $
0013 %   - If you specify the name, then you should be specify title and ext.
0014 %
0015 % $ History $
0016 %   - Created by Dahua Lin, on Aug 12nd, 2006
0017 %
0018 
0019 %% Main body
0020 
0021 if isempty(varargin)
0022     newfp = fp;
0023 else
0024     
0025     opts.parent = '';
0026     opts.name = '';
0027     opts.title = '';
0028     opts.ext = '';
0029     opts = slparseprops(opts, varargin{:});
0030     
0031     if ~isempty(opts.ext)
0032         if opts.ext(1) ~= '.'
0033             error('sltoolbox:invalidarg', ...
0034                 'The extension string should start with a dot . ');
0035         end
0036     end
0037     
0038     [p.parent, p.title, p.ext] = fileparts(fp);
0039     
0040     if isempty(opts.name)
0041         p = updatefields(p, opts, {'parent', 'title', 'ext'});
0042         newfp = fullfile(p.parent, [p.title, p.ext]);
0043     else        
0044         if ~isempty(opts.title) || ~isempty(opts.ext)
0045             error('sltoolbox:invalidarg', ...
0046                 'When name is specified, title and ext should not be');
0047         end
0048         p = updatefields(p, opts, {'parent', 'name'});
0049         newfp = fullfile(p.parent, p.name);
0050     end
0051         
0052 end
0053 
0054 
0055 %% Auxiliary functions
0056 
0057 function S = updatefields(S, newS, fns)
0058 
0059 nf = length(fns);
0060 for i = 1 : nf
0061     f = fns{i};
0062     if ~isempty(newS.(f))
0063         S.(f) = newS.(f);
0064     end
0065 end
0066 
0067     
0068 
0069 
0070 
0071 
0072 
0073     
0074

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com