-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGaborThresholdTrials.m
44 lines (38 loc) · 1.14 KB
/
GaborThresholdTrials.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
function [Data , test_trials] = GaborThresholdTrials(Data, phase, threshold, floor)
if phase == 0
stair_param = 'contrast';
elseif phase == 1
stair_param = 'true_ratio';
elseif phase == 2
stair_param = 'noise';
end
test_trials = Data.(stair_param) <= threshold;
if exist('floor', 'var')
test_trials = test_trials & Data.(stair_param) >= floor;
end
%% Subselect trial data.
Data.current_trial = sum(test_trials);
Data = maskFieldsDetectDimension(Data, test_trials);
end
function str = maskFieldsDetectDimension(str, mask)
% Apply logical mask to fields in the given struct, automatically detecting which fields and which
% dimension of those fields need processing based on their length.
nTrials = length(mask);
fields = fieldnames(str);
for iField=1:length(fields)
needsMask = false;
val = str.(fields{iField});
dims = ndims(val);
ref = struct('type', '()', 'subs', {repmat({':'}, 1, dims)});
for d=1:dims
if size(val, d) == nTrials
ref.subs{d} = mask;
needsMask = true;
break
end
end
if needsMask
str.(fields{iField}) = subsref(val, ref);
end
end
end