home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / BarlaA / sw / matlab / Cromwell / truncateName.m < prev    next >
Text File  |  2007-12-04  |  794b  |  22 lines

  1. function dataname = truncateName(filename)
  2. % dataname = truncateName(filename)
  3. %
  4. % This function takes as its input a string representing a file name.
  5. % It strips off the extension (everything after the final '.') to
  6. % create a a variable name. In order to ensure that the variable name
  7. % is valid in MATLAB, it replaces everything that is not a normal
  8. % letter or digit with an underscore.
  9.  
  10. % Copyright (c) 2003, 2004 UT M.D. Anderson Cancer Center. All rights reserved.
  11. % See the accompanying file "license.txt" for details.
  12.  
  13. tmp = findstr(filename, '.');
  14. if length(tmp) > 0,
  15.    tmp = tmp(end)-1;
  16.    dataname = char(filename(1:tmp));
  17. else
  18.    dataname = char(filename);
  19. end
  20. badchar = find(~isletter(dataname) & ~ismember(dataname, '0123456789'));
  21. dataname(badchar) = '_';
  22.