-
Notifications
You must be signed in to change notification settings - Fork 2
/
ptb_addpath.m
62 lines (55 loc) · 1.99 KB
/
ptb_addpath.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function pathlist = ptb_addpath(add, ptbpath, folderlist)
% pathlist = ptb_addpath(add, ptbpath, folderlist)
%
% Adds functions to Matlab Path (useful when developing new programs). This
% function is not recommended to be used in actual/main experiments.
% 1. Functions in 'PTB-Exp-Builder/' will be added by default.
% 2. If PTB-Exp-Builder/' is not avaiable in Matlab Path, 'functions/' in
% pwd (if available) will be added to Matlab Path.
% 3. If 'functions/' is not avaiable in pwd, <folderlist> in the pwd will
% be added to Matlab Path.
%
% Inputs:
% add <boo> whether add <pathlist> from Matlab Path.
% Default is 1.
% ptbpath <str> where folders in <folderlist> are.
% folderlist <cell str> folders to be added to Matlab Path.
%
% Output:
% pathlist <cell str> list of folders added to /removed from
% Matlab path.
%
% Created by Haiyang Jin (2021-11-22)
if ~exist('folderlist', 'var') || isempty(folderlist)
folderlist = {filesep}; % {'PTB/', 'fMRI/', 'ImageTools/', 'Utilities/'};
end
if ischar(folderlist)
folderlist = {folderlist};
end
if ~exist('ptbpath', 'var') || isempty(ptbpath)
% use functions in PTB-Exp-Builder by default
ptbpath = fileparts(which('ptb_addpath'));
% ptbpath = fileparts(matlab.desktop.editor.getActiveFilename);
% ptbpath = fileparts(mfilename('fullpath'));
end
if isempty(ptbpath)
% if PTB-Exp-Builder is not added to path, use 'functions/' in pwd.
ptbpath = 'functions/';
end
if ~exist('add', 'var') || isempty(add)
add = 1;
end
% add all avaiable folders to Matlab path
pathlist = fullfile(ptbpath, folderlist)';
if add
cellfun(@(x) addpath(genpath(x)), pathlist);
else
cellfun(@(x) rmpath(genpath(x)), pathlist);
addpath(ptbpath);
end
% display message
dirstr = {'removed from', 'added to'};
fprintf(['\nFollowing directories (and its subdirectories) have been' ...
' %s Matlab path:\n%s'], ...
dirstr{add+1}, sprintf('%s\n', pathlist{:}));
end