time | Calls | line |
---|
| | 1 | function p = path(path1,path2)
|
| | 2 | %PATH Get/set search path.
|
| | 3 | % PATH, by itself, prettyprints MATLAB's current search path. The initial
|
| | 4 | % search path list is set by PATHDEF, and is perhaps individualized by
|
| | 5 | % STARTUP.
|
| | 6 | %
|
| | 7 | % P = PATH returns a character vector containing the path in P. PATH(P)
|
| | 8 | % changes the path to P.
|
| | 9 | %
|
| | 10 | % PATH(P1,P2) changes the path to the concatenation of the two search
|
| | 11 | % paths P1 and P2. Thus PATH(PATH,P) appends the folder P to the
|
| | 12 | % current path and PATH(P,PATH) prepends the folder P. If P is already
|
| | 13 | % on the path, then PATH(PATH,P) moves P to the end of the path,
|
| | 14 | % and similarly, PATH(P,PATH) moves P to the beginning of the path.
|
| | 15 | %
|
| | 16 | % For example, the following statements add another folder to MATLAB's
|
| | 17 | % search path on various operating systems:
|
| | 18 | %
|
| | 19 | % Unix: path(path,'/home/myfriend/goodstuff')
|
| | 20 | % Windows: path(path,'c:\tools\goodstuff')
|
| | 21 | %
|
| | 22 | % See also WHAT, CD, DIR, ADDPATH, RMPATH, GENPATH, PATHTOOL, SAVEPATH, REHASH.
|
| | 23 |
|
| | 24 | % Copyright 1984-2017 The MathWorks, Inc.
|
| | 25 |
|
< 0.001 | 3 | 26 | if nargin == 0 % Pretty-print
|
| | 27 | if nargout == 0
|
| | 28 | matlabpath
|
| | 29 | end
|
< 0.001 | 3 | 30 | elseif nargin == 1
|
| | 31 | if ~isValidInput(path1)
|
| | 32 | error(message('MATLAB:string:MustBeStringScalarOrCharacterVector'))
|
| | 33 | end
|
| | 34 | matlabpath(path1) % matlabpath will check and process path1
|
< 0.001 | 3 | 35 | elseif nargin == 2
|
0.001 | 3 | 36 | if ~isValidInput(path2) || ~isValidInput(path1)
|
| | 37 | error(message('MATLAB:string:MustBeStringScalarOrCharacterVector'))
|
| | 38 | end
|
| | 39 |
|
| | 40 | % If path1 is contained in path2 or vice versa, don't add it
|
0.003 | 3 | 41 | pp = matlabpath;
|
| | 42 | % Windows is case-insensitive
|
| | 43 | % Use "Cased" variables for comparisons,
|
| | 44 | % but do real work on path1 and path2
|
| | 45 | % Define FILESEP and PATHSEP, since these are not built-in
|
| | 46 | % and PATH might be called with an empty MATLAB path
|
0.001 | 3 | 47 | if strncmp(computer,'PC',2)
|
| | 48 | ps = ';';
|
| | 49 | path1 = strrep(path1,'/','\');
|
| | 50 | path2 = strrep(path2,'/','\');
|
| | 51 | path1Cased = lower(path1);
|
| | 52 | path2Cased = lower(path2);
|
| | 53 | ppCased = lower(pp);
|
< 0.001 | 3 | 54 | else
|
< 0.001 | 3 | 55 | ps = ':';
|
< 0.001 | 3 | 56 | path1Cased = path1;
|
< 0.001 | 3 | 57 | path2Cased = path2;
|
< 0.001 | 3 | 58 | ppCased = pp;
|
< 0.001 | 3 | 59 | end
|
| | 60 |
|
< 0.001 | 3 | 61 | if isempty(path1Cased)
|
| | 62 | if ~strcmp(ppCased,path2Cased), matlabpath(path2), end
|
< 0.001 | 3 | 63 | elseif isempty(path2Cased)
|
| | 64 | if ~strcmp(ppCased,path1Cased), matlabpath(path1), end
|
< 0.001 | 3 | 65 | else
|
| | 66 | % Check for special cases path(path1,path) or path(path,path2)
|
< 0.001 | 3 | 67 | if strcmp(ppCased,path1Cased), append = 1; else append = 0; end
|
| | 68 |
|
| | 69 | % Add path separator to path1 and path2
|
< 0.001 | 3 | 70 | if ~isempty(path1Cased) && path1Cased(end)~=ps, path1 = strcat(path1,ps); end
|
0.012 | 3 | 71 | if ~isempty(path2Cased) && path2Cased(end)~=ps, path2 = strcat(path2,ps); end
|
| | 72 |
|
0.011 | 3 | 73 | cPath1 = parsedirs(path1);
|
0.025 | 3 | 74 | cPath2 = parsedirs(path2);
|
| | 75 |
|
| | 76 | % Use "Cased" variables for comparisons,
|
| | 77 | % but do real work on cPath1 and cPath2
|
< 0.001 | 3 | 78 | if strncmp(computer,'PC',2)
|
| | 79 | cPath1Cased = lower(cPath1);
|
| | 80 | cPath2Cased = lower(cPath2);
|
< 0.001 | 3 | 81 | else
|
< 0.001 | 3 | 82 | cPath1Cased = cPath1;
|
< 0.001 | 3 | 83 | cPath2Cased = cPath2;
|
< 0.001 | 3 | 84 | end
|
| | 85 |
|
| | 86 | % Loop through path to see if we're adding existing paths
|
| | 87 | % If so, move them to the beginning or end as specified
|
| | 88 | % On Windows, search without case, but use actual inputs when
|
| | 89 | % calling MATLABPATH to preserve case
|
< 0.001 | 3 | 90 | if append
|
| | 91 | pmatch = false(size(cPath1));
|
| | 92 | for n=1:length(cPath2Cased)
|
| | 93 | pmatch = pmatch | strcmp(cPath2Cased{n},cPath1Cased);
|
| | 94 | end
|
| | 95 | cPath1(pmatch) = [];
|
< 0.001 | 3 | 96 | else
|
< 0.001 | 3 | 97 | pmatch = false(size(cPath2));
|
< 0.001 | 3 | 98 | for n=1:length(cPath1Cased)
|
0.021 | 954 | 99 | pmatch = pmatch | strcmp(cPath1Cased{n},cPath2Cased);
|
< 0.001 | 954 | 100 | end
|
< 0.001 | 3 | 101 | cPath2(pmatch) = [];
|
< 0.001 | 3 | 102 | end
|
| | 103 |
|
< 0.001 | 3 | 104 | if isempty(cPath2)
|
| | 105 | matlabpath(path1);
|
< 0.001 | 3 | 106 | elseif isempty(cPath1)
|
| | 107 | matlabpath(path2);
|
< 0.001 | 3 | 108 | else
|
0.166 | 3 | 109 | matlabpath([cPath1{:} cPath2{:}]);
|
< 0.001 | 3 | 110 | end
|
< 0.001 | 3 | 111 | end
|
< 0.001 | 3 | 112 | end
|
| | 113 |
|
< 0.001 | 3 | 114 | if nargout==1, p = matlabpath; end
|
Other subfunctions in this file are not included in this listing.