-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetPath.m
44 lines (36 loc) · 1.09 KB
/
setPath.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
%
% setPath()
% setPath(setNewPathFlag)
%
% Clears the Matlab path and sets it for this project.
% Do not move this function to another folder!
%
% setNewPathFlag: Optional, set to false to reset the original path. (default: true)
%
function setPath(setNewPathFlag)
persistent user_path_backup;
if nargin < 1
setNewPathFlag = true;
end
if setNewPathFlag
updateOnly = exist('user_path_backup', 'var');
user_path_backup = path();
folder = fileparts(mfilename('fullpath'));
if ~updateOnly
sprintf('Clearing Matlab path and setting it for this project to %s...\n', folder);
restoredefaultpath();
else
sprintf('Updating Matlab path and setting it for this project to %s...\n', folder);
end
addpath(genpath(folder));
disp('Done setting path. Enter ''resetPath'' to return to the previously set path.');
else
if ~isempty(user_path_backup)
disp('Resetting Matlab path to the previously set path...');
path(user_path_backup);
else
disp('No previously set Matlab path known...');
end
user_path_backup = [];
end
end