% --------------------------------------------------------------------------------- % % Name: ModelPathSetup.m % Author: Alan Brooks % Project: Any multi-folder MATLAB (version R11, R12, R13) model. % Description: This function modifies the MATLAB path by adding the % path it resides in and then recursively adding the % subpaths of this path. % Inputs: disp_on % 1 = display, 0 = supress display % Outputs: % Example Function Call: % >> ModelPathSetup(0); % % Revisions: % 09/19/2001 - created function % 10/01/2001 - added local function genpath for version compatibility % % --------------------------------------------------------------------------------- function [] = ModelPathSetup(disp_on); % ----- Variables ----------------------------------------------------------------- if (nargin < 1), disp_on = 1; end; % ----- Begin Procedure ----------------------------------------------------------- ThisDir = what; P = genpathAB(ThisDir.path); addpath(P) if disp_on, disp('Path and all subpaths added.'); end; return; % ----- End of Main Function ------------------------------------------------------ %%%%%%%%%%%%%%%%%%%%%%%%%%%% Local Function %%%%%%%%%%%%%%%%%%% function p = genpathAB(d) %GENPATH Generate recursive toolbox path. (from MATLAB R12) % P = GENPATH returns a new path string by adding % all the directories below MATLABROOT/toolbox. % % P = GENPATH(D) returns a path string formed by % recursively adding all the directories below D. % Copyright 1984-2000 The MathWorks, Inc. % $Revision: 1.9 $ $Date: 2000/06/01 19:52:50 $ if nargin==0, p = genpath(fullfile(matlabroot,'toolbox')); if length(p) > 1, p(end) = []; end % Remove trailing pathsep return end % Generate path based on given root directory files = dir(d); if isempty(files) return end % % Add d to the path if it contains files, otherwise don't % bother. For example, toolbox\matlab contains only directories % which makes it unneccessary to add this directory to the path. % On the other hand toolbox\matlab\general, for example, contains % files that users may want to access. % p = ''; isdir = logical(cat(1,files.isdir)); if ~all(isdir) p = [p d pathsep]; end % % Recursively descend through directories which are neither % private nor "class" directories. % methodsep = '@'; dirs = files(isdir); for i=1:length(dirs) dirname = dirs(i).name; if ~strcmp( dirname,'.') &... ~strcmp( dirname,'..') &... ~strncmp(dirname,methodsep,1) &... ~strcmp( dirname,'private') p = [p genpath(fullfile(d,dirname))]; end end % ----- End of File ---------------------------------------------------------------