NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/util/path2cell.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function pathlist = path2cell(pathstr)
2 %PATH2CELL Convert search path to cell array.
3 %
4 %   PATH2CELL returns a cell array where each element is a directory
5 %   in the search path.
6 %
7 %   PATH2CELL(MYPATH) converts MYPATH rather than the search path.
8 %
9 %   Empty directories are removed, so under UNIX, PATH2CELL('foo::bar')
10 %   returns { 'foo' 'bar' } rather than { 'foo' '' 'bar' }.
11
12 %   Author:      Peter J. Acklam
13 %   Time-stamp:  2000-02-24 15:19:09
14 %   E-mail:      jacklam@math.uio.no
15 %   URL:         http://www.math.uio.no/~jacklam
16
17    % Check number of input arguments.
18    error(nargchk(0, 1, nargin));
19
20    % Use Matlab's search path if no input path is given.
21    if ~nargin
22       pathstr = path;
23    end
24
25    k = find( pathstr == pathsep );         % Find path separators.
26    k = [ 0 k length(pathstr)+1 ];          % Find directory boundaries.
27    ndirs = length(k)-1;                    % Number of directories.
28    pathlist = cell(0);                     % Initialize output argument.
29    for i = 1:ndirs
30       dir = pathstr( k(i)+1 : k(i+1)-1 );  % Get i'th directory.
31       if ~isempty(dir)                     % If non-empty...
32          pathlist{end+1,1} = dir;          % ...append to list.
33       end
34    end
Note: See TracBrowser for help on using the browser.