


PATH2CELL Convert search path to cell array.
PATH2CELL returns a cell array where each element is a directory
in the search path.
PATH2CELL(MYPATH) converts MYPATH rather than the search path.
Empty directories are removed, so under UNIX, PATH2CELL('foo::bar')
returns {'foo', 'bar'} rather than {'foo', '', 'bar'}.

0001 function pathlist = path2cell(pathstr) 0002 %PATH2CELL Convert search path to cell array. 0003 % 0004 % PATH2CELL returns a cell array where each element is a directory 0005 % in the search path. 0006 % 0007 % PATH2CELL(MYPATH) converts MYPATH rather than the search path. 0008 % 0009 % Empty directories are removed, so under UNIX, PATH2CELL('foo::bar') 0010 % returns {'foo', 'bar'} rather than {'foo', '', 'bar'}. 0011 0012 % Author: Peter J. Acklam 0013 % Time-stamp: 2001-10-18 21:23:19 +0200 0014 % E-mail: pjacklam@online.no 0015 % URL: http://home.online.no/~pjacklam 0016 0017 % check number of input arguments 0018 error(nargchk(0, 1, nargin)); 0019 0020 % use MATLAB's search path if no input path is given 0021 if ~nargin 0022 pathstr = path; 0023 end 0024 0025 k = find(pathstr == pathsep); % find path separators 0026 k = [0 k length(pathstr)+1]; % find directory boundaries 0027 ndirs = length(k)-1; % number of directories 0028 pathlist = cell(0); % initialize output argument 0029 for i = 1 : ndirs 0030 dir = pathstr(k(i)+1 : k(i+1)-1); % get i'th directory 0031 if ~isempty(dir) % if non-empty... 0032 pathlist{end+1,1} = dir; % ...append to list 0033 end 0034 end