Home > vbmeg > functions > common > utility > vb_change_file_basename.m

vb_change_file_basename

PURPOSE ^

change basename of file for predefined extension

SYNOPSIS ^

function [fname ,basename, fext] = vb_change_file_basename(fold, addname, ext0)

DESCRIPTION ^

 change basename of file for predefined extension
  [fname ,basename, ext] = vb_change_file_basename(fold, addname)
  [fname ,basename, ext] = vb_change_file_basename(fold, addname, ext)
 --- Input
 fold    : old file name = [ old_basename  extension ]
 addname : this string is added to the basename of the file name
 --- Optional input
 ext     : extension
    If this variable is not specified, 
    predefined extensions is used
 --- Output
 basename = [ old_basename  addname ]
 fname    : new file name = [ basename  extension ]
 ext      : extension
 --- Predefined extensions
  '.brain.mat';
  '.area.mat';
  '.act.mat';
  '.basis.mat';
  '.meg.mat';
  '.bayes.mat';
  '.curr.mat' ;
  '.xyz.mat';
  '.atlas.mat';

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [fname ,basename, fext] = vb_change_file_basename(fold, addname, ext0)
0002 % change basename of file for predefined extension
0003 %  [fname ,basename, ext] = vb_change_file_basename(fold, addname)
0004 %  [fname ,basename, ext] = vb_change_file_basename(fold, addname, ext)
0005 % --- Input
0006 % fold    : old file name = [ old_basename  extension ]
0007 % addname : this string is added to the basename of the file name
0008 % --- Optional input
0009 % ext     : extension
0010 %    If this variable is not specified,
0011 %    predefined extensions is used
0012 % --- Output
0013 % basename = [ old_basename  addname ]
0014 % fname    : new file name = [ basename  extension ]
0015 % ext      : extension
0016 % --- Predefined extensions
0017 %  '.brain.mat';
0018 %  '.area.mat';
0019 %  '.act.mat';
0020 %  '.basis.mat';
0021 %  '.meg.mat';
0022 %  '.bayes.mat';
0023 %  '.curr.mat' ;
0024 %  '.xyz.mat';
0025 %  '.atlas.mat';
0026 %
0027 % Copyright (C) 2011, ATR All Rights Reserved.
0028 % License : New BSD License(see VBMEG_LICENSE.txt)
0029 
0030 if exist('ext0','var'),
0031     ext{1} = ext0;
0032 else
0033     ext{1} = '.brain.mat';
0034     ext{2} = '.area.mat';
0035     ext{3} = '.act.mat';
0036     ext{4} = '.basis.mat';
0037     ext{5} = '.meg.mat';
0038     ext{6} = '.bayes.mat';
0039     ext{7} = '.curr.mat' ;
0040     ext{8} = '.xyz.mat';
0041     ext{9} = '.atlas.mat';
0042 end
0043 
0044 Next   = length(ext);
0045 
0046 for n = 1:Next
0047     fext   = ext{n};
0048     ix_ext = findstr(fold, fext);
0049 
0050     if ~isempty(ix_ext),
0051         basename = fold(1:ix_ext-1);
0052         basename = [basename addname];
0053         fname = [ basename fext];
0054         return
0055     end
0056 end
0057 
0058 % No match
0059 fname = fold;
0060 basename = [];
0061 fext = [];

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005