-
Notifications
You must be signed in to change notification settings - Fork 1
/
DMAddPaths.m
48 lines (33 loc) · 1.37 KB
/
DMAddPaths.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function DMAddPaths(varargin)
force = nargin > 0 && strcmp(varargin{1}, 'force');
% This version number should be incremented whenever new paths are added to
% the list
DMAddPaths_Version_Number = 1;
persistent DM_PathsHaveBeenSet
full_path = mfilename('fullpath');
[path_root, ~, ~] = fileparts(full_path);
if force || (isempty(DM_PathsHaveBeenSet) || DM_PathsHaveBeenSet ~= DMAddPaths_Version_Number)
path_folders = {};
% List of folders to add to the path
path_folders{end + 1} = '';
path_folders{end + 1} = fullfile('External', 'coremat');
AddToPath(path_root, path_folders)
CoreAddPaths(varargin{:});
DM_PathsHaveBeenSet = DMAddPaths_Version_Number;
end
end
function AddToPath(path_root, path_folders)
full_paths_to_add = {};
% Get the full path for each folder but check it exists before adding to
% the list of paths to add
for i = 1 : length(path_folders)
full_path_name = fullfile(path_root, path_folders{i});
if exist(full_path_name, 'dir')
full_paths_to_add{end + 1} = full_path_name;
end
end
% Add all the paths together (much faster than adding them individually)
if ~isempty(full_paths_to_add)
addpath(full_paths_to_add{:});
end
end