function theResult = at(theFile, theOffset) % at -- Switch to the folder of a given file. % at('theFunction') switches to the folder of % 'theFunction', as determined by the "which" % function. % at('theFunction', theOffset) performs as above, % then marches into higher directories by the % amount of theOffset, which must be a negative % integer. % Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 01-Feb-2000 22:21:09. % Updated 22-Apr-2003 09:19:37. if nargout > 0, theResult = []; end if nargin < 1, help(mfilename), return, end if nargin < 2, theOffset = 0; end if ischar(theOffset), theOffset = eval(theOffset); end w = which(theFile); if isempty(w) w = which([theFile '/' theFile]); if isempty(w) disp([' ## No such file: ' theFile]) return end elseif isequal(w, 'built-in') disp([' ## ' theFile ' is built-in. Try "at ' theFile '.m".']) return end [thePath, theName, theExtension, theVersion] = fileparts(w); if any(thePath) cd(thePath) if theOffset < 0 for i = 1:fix(abs(theOffset)) cd .. end end end if nargout > 0 theResult = pwd; else disp([' ## ' pwd]) end