time   | Calls   |  line  | 
|---|
 |  |    1   | function oldpath = addpath(varargin)
   | 
 |  |    2   | %ADDPATH Add folder to search path.
   | 
 |  |    3   | %   ADDPATH FOLDERNAME prepends the specified folder to the current
   | 
 |  |    4   | %   matlabpath.  Surround FOLDERNAME in quotes if the name contains a
   | 
 |  |    5   | %   space.  If FOLDERNAME is a set of multiple folders separated by path
   | 
 |  |    6   | %   separators, then each of the specified folders will be added.
   | 
 |  |    7   | %
   | 
 |  |    8   | %   ADDPATH FOLDERNAME1 FOLDERNAME2 FOLDERNAME3 ...  prepends all the 
   | 
 |  |    9   | %   specified folders to the path.
   | 
 |  |   10   | %
   | 
 |  |   11   | %   ADDPATH ... -END    appends the specified folders.
   | 
 |  |   12   | %   ADDPATH ... -BEGIN  prepends the specified folders.
   | 
 |  |   13   | %   ADDPATH ... -FROZEN disables folder change detection for folders
   | 
 |  |   14   | %                       being added.
   | 
 |  |   15   | %
   | 
 |  |   16   | %   Use the functional form of ADDPATH, such as 
   | 
 |  |   17   | %   ADDPATH('folder1','folder2',...), when the folder specification is 
  | 
 |  |   18   | %   a variable or string.
   | 
 |  |   19   | %
   | 
 |  |   20   | %   P = ADDPATH(...) returns the path prior to adding the specified paths.
   | 
 |  |   21   | %
   | 
 |  |   22   | %   Examples
   | 
 |  |   23   | %       addpath c:\matlab\work
   | 
 |  |   24   | %       addpath /home/user/matlab
   | 
 |  |   25   | %       addpath /home/user/matlab:/home/user/matlab/test:
   | 
 |  |   26   | %       addpath /home/user/matlab /home/user/matlab/test
   | 
 |  |   27   | %
   | 
 |  |   28   | %   See also RMPATH, PATHTOOL, PATH, SAVEPATH, USERPATH, GENPATH, REHASH.
   | 
 |  |   29   | 
 
  | 
 |  |   30   | %   Copyright 1984-2017 The MathWorks, Inc.
   | 
 |  |   31   | 
 
  | 
 |  |   32   | % Number of  input arguments
   | 
< 0.001   |       3   |   33  | n = nargin; 
   | 
< 0.001   |       3   |   34  | narginchk(1,Inf); 
   | 
< 0.001   |       3   |   35  | [varargin{:}] = convertStringsToChars(varargin{:}); 
  | 
 |  |   36   | 
 
  | 
< 0.001   |       3   |   37  | if nargout>0 
   | 
 |  |   38   |     oldpath = path;
   | 
 |  |   39   | end
   | 
 |  |   40   | 
 
  | 
< 0.001   |       3   |   41  | append = -1; 
   | 
< 0.001   |       3   |   42  | freeze = 0; 
   | 
< 0.001   |       3   |   43  | args = varargin; 
   | 
 |  |   44   | 
 
  | 
< 0.001   |       3   |   45  | while (n > 1)    
   | 
 |  |   46   |     last = args{n};
  | 
 |  |   47   |     % Append or prepend to the existing path
   | 
 |  |   48   |     if isequal(last,1) || strcmpi(last,'-end')
   | 
 |  |   49   |         if (append < 0), append = 1; end; 
   | 
 |  |   50   |         n = n - 1;
   | 
 |  |   51   |     elseif isequal(last,0) || strcmpi(last,'-begin')
   | 
 |  |   52   |         if (append < 0), append = 0; end;
   | 
 |  |   53   |         n = n - 1;
   | 
 |  |   54   |     elseif strcmpi(last,'-frozen') 
   | 
 |  |   55   |         freeze = 1;
   | 
 |  |   56   |         n = n - 1;
   | 
 |  |   57   |     else
   | 
 |  |   58   |         break;
   | 
 |  |   59   |     end
   | 
 |  |   60   | end
   | 
< 0.001   |       3   |   61  | if (append < 0), append = 0; end 
   | 
 |  |   62   | 
 
  | 
 |  |   63   | % Check, trim, and concatenate the input strings
   | 
  0.004   |       3   |   64  | p = catdirs(mfilename, varargin{1:n}); 
  | 
 |  |   65   | 
 
  | 
 |  |   66   | % If p is empty then return
   | 
< 0.001   |       3   |   67  | if isempty(p) 
   | 
 |  |   68   |     return;
   | 
< 0.001   |       3   |   69  | elseif ~isempty(strfind(p, char(0))) 
   | 
 |  |   70   |     error(message('MATLAB:FileManip:NullCharacterInName'));
  | 
 |  |   71   | end
   | 
 |  |   72   | 
 
  | 
 |  |   73   | % See whether frozen is desired, where the state is not already set frozen
   | 
< 0.001   |       3   |   74  | if freeze 
   | 
 |  |   75   |     if feature('IsPM2.0')
  | 
 |  |   76   |         paths = strsplit(p,pathsep());
   | 
 |  |   77   |         for n = 1:size(paths,2)-1
   | 
 |  |   78   |             feature('DirectoryFreeze',paths{n});
  | 
 |  |   79   |         end
   | 
 |  |   80   |     else
   | 
 |  |   81   |         oldfreeze = system_dependent('DirsAddedFreeze');
  | 
 |  |   82   |         % Check whether old unfrozen state needs to be restored
   | 
 |  |   83   |         if ~isempty(strfind(oldfreeze,'unfrozen'))
   | 
 |  |   84   |             %Use the onCleanup object to automatically restore old state at
   | 
 |  |   85   |             %exit or error.
   | 
 |  |   86   |             cleanUp = onCleanup(@()system_dependent('DirsAddedUnfreeze'));
  | 
 |  |   87   |         end
   | 
 |  |   88   |     end
   | 
 |  |   89   | end
   | 
 |  |   90   | 
 
  | 
 |  |   91   | % Append or prepend the new path
   | 
  0.003   |       3   |   92  | mp = matlabpath; 
   | 
< 0.001   |       3   |   93  | if append 
   | 
 |  |   94   |     path(mp, p);
   | 
< 0.001   |       3   |   95  | else 
   | 
  0.277   |       3   |   96  |     path(p, mp); 
   | 
< 0.001   |       3   |   97  | end     
   | 
Other subfunctions in this file are not included in this listing.