ET_PDToolkit/PDToolkit/@PDTrial/getIndexForEvent.m

43 lines
1.4 KiB
Matlab

function[index] = getIndexForEvent(objs, event)
ton_codings = {'trial onset','trial on', 'start trial', 'trial start', 'trial_start'};
toff_codings = {'trial offset','trial off', 'end trial', 'trial end', 'trial_end'};
son_codings = {'stimulus onset','stimulus on', 'soa', 'stim on', 'stim_on', 'stimulus start', 'stim_start'};
soff_codings = {'stimulus offset','stimulus off', 'stim off', 'stim_off', 'stim end', 'stim_end'};
bon_codings = {'baseline on', 'baseline start', 'baseline onset', 'bl on', 'bl'};
boff_codings = {'baseline off', 'baseline end', 'baseline offset', 'bl off'};
all_codings = [ton_codings toff_codings son_codings soff_codings bon_codings boff_codings];
for o = 1:length(objs)
obj = objs(o);
if ismember(event, son_codings)
time = obj.stimulus_onset;
end
if ismember(event, soff_codings)
time = obj.stimulus_offset;
end
if ismember(event, bon_codings)
time = obj.baseline_onset;
end
if ismember(event, boff_codings)
time = obj.baseline_offset;
end
if ~ismember(event, all_codings)
%% search for label
ind = regexp(event, [obj.labels.name]);
time = obj.labels(ind).time;
end
pre_ind = find(obj.time <= time);
if isempty(pre_ind)
event_index = NaN;
else
event_index = pre_ind(end);
end
index(o) = event_index;
end