-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsDefineStudyExamples.m
146 lines (122 loc) · 4.33 KB
/
psDefineStudyExamples.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
% studies = psDefineStudyExamples(studyfolder,withoutQuestions)
%
%
% Example
% psDefineStudyExamples([],1) % without asking questions
function studies = psDefineStudyExamples(studyfolder,withoutQuestions)
if ~exist('studyfolder','var') || isempty(studyfolder)
studyfolder = 'Studies';
end
if ~exist('withoutQuestions','var') || isempty(withoutQuestions)
withoutQuestions = 0;
end
if ~exist(studyfolder,'dir')
error('studyfolder %s does not exist.',studyfolder)
end
d = dir(studyfolder);
ds = {d.name};
ds = ds([d.isdir]);
ds = setdiff(ds(3:end),'project_lib'); % eliminate '.' and '..'
if exist('fileChooser')~=2
arCheck
end
if withoutQuestions
in = 'y';
else
askstring = sprintf('Do you wish to standard setting? [yes: Press button or ''y'', no=select/check options: type ''n'', CTRL+c for exit] ');
in = deblank(input(askstring,'s'));
end
if strcmpi(in,'y') || strcmpi(in,'yes')
useDefault = 1;
else
useDefault = 0;
end
studies = [];
for i=1:length(ds)
disp('---------------------------')
fprintf('Study #%3i (''%s'') : ',i,ds{i});
if ~useDefault
in = lower(deblank(input('To be analyzed? [yes: Press button, no: type ''n''] ','s')));
else
in = 'y';
end
if(isempty(in) || strcmpi(in,'y') || strcmpi(in,'yes'))
fprintf('OK, %s selected.\n\n',ds{i})
if isempty(studies)
studies = newStudyDesign;
else
studies(end+1) = newStudyDesign;
end
studies(end).name = ds{i};
studies(end).path = [studyfolder,filesep,ds{i}];
d2 = dir(studies(end).path);
fs = {d2.name};
fs = fs(~[d2.isdir]);
ind = strmatch('setup',lower(fs));
if(isempty(ind))
warning('No Setup file found => no fun_setup assigned.')
elseif length(ind)==1
if ~useDefault
in = input(sprintf('Assign %s as setup function ''fun_setup''? [yes: Press button or ''y'', no: type ''n'']',fs{ind}),'s');
else
in = 'y';
end
if(isempty(in) || strcmpi(in,'y') || strcmpi(in,'yes'))
[~,studies(end).fun_setup] = fileparts(fs{ind});
else
disp('No fun_setup assigned.')
end
else
if ~useDefault
disp('Please select the appropriate setup file: [type a number]');
for j=1:length(ind)
fprintf(' #%3i : %s\n',j,fs{ind(j)});
end
in = str2num(input(sprintf('Please choose (1-%i) or empty for none: ',length(ind)),'s'));
else
in = 1;
end
if(~isempty(in))
[~,studies(end).fun_setup] = fileparts(fs{ind(in)});
fprintf('OK, setup %s selected.\n\n',studies(end).fun_setup);
else
disp('No fun_setup assigned.')
end
end
d3 = dir([studies(end).path,filesep,'Results\']);
ws = {d3.name};
ws = ws([d3.isdir]);
ws = ws(3:end);
if ~isempty(ws)
if ~useDefault
disp('If parameters should be loaded, please choose one of the available workspaces:');
for j=1:length(ws)
fprintf('#%3i : %s\n',j,ws{j});
end
in = str2num(input(sprintf('Please choose (1-%i) : ',length(ws)),'s'));
else
[~,~,ia] = intersect(lower('BestFit'),lower(ws));
if ~isempty(ia)
in = ia;
else
in = 1; % default workspace
end
end
if(isempty(in))
disp('No workspace selected');
else
studies(end).workspace = ws{in};
fprintf('OK, parameters will be loaded from %s.\n',ws{in});
end
else
disp('No workspaces available for loading parameters.')
end
end
end
function s = newStudyDesign
s.name = '';
s.date = datestr(now,30);
s.path = '';
s.fun_setup = '';
s.fun_analysis = '';
s.workspace = '';