function[objs] = setPatternRelativeToPattern(objs, relativeTotype,type, timing) %% Specify a new marker/pattern relative in time to an existing pattern % time should be milliseconds (ms). if ~isnumeric(timing) error('Timing is not numeric'); end 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'}; soff_codings = {'stimulus offset','stimulus off', 'stim off', 'stim_off'}; bon_codings = {'baseline on', 'baseline start', 'baseline onset', 'bl on', 'bl'}; boff_codings = {'baseline off', 'baseline end', 'baseline offset', 'bl off'}; ton = ismember(lower(relativeTotype), ton_codings); toff = ismember(lower(relativeTotype), toff_codings); son = ismember(lower(relativeTotype), son_codings); soff = ismember(lower(relativeTotype), soff_codings); bon = ismember(lower(relativeTotype), bon_codings); boff = ismember(lower(relativeTotype), boff_codings); types = [ton toff son soff bon boff]; type_ind = find(types==1); for i = 1:length(objs) obj = objs(i); if isempty(type_ind) error('No correct type entered'); else err=0; switch type_ind case 1 if (isempty(obj.trial_start_pattern)), err=1; else target = 'trial_start'; end case 2 if (isempty(obj.trial_end_pattern)), err=1; else target = 'trial_end'; end case 3 if (isempty(obj.stimulus_onset_pattern)), err=1; else target = 'stimulus_onset'; end case 4 if (isempty(obj.stimulus_offset_pattern)), err=1; else target = 'stimulus_offset'; end case 5 if (isempty(obj.baseline_onset_pattern)), err=1; else target = 'baseline_onset'; end case 6 if (isempty(obj.baseline_offset_pattern)), err=1; else target = 'baseline_offset'; end end end if err error('Dependent type has not been defined'); end if (ismember(lower(type), ton_codings)) obj.trial_start_pattern = {timing target}; end if (ismember(lower(type), toff_codings)) obj.trial_end_pattern = {timing target}; end if (ismember(lower(type), son_codings)) obj.stimulus_onset_pattern = {timing target}; end if (ismember(lower(type), soff_codings)) obj.stimulus_onset_pattern = {timing target}; end if (ismember(lower(type), bon_codings)) obj.baseline_onset_pattern = {timing target}; end if (ismember(lower(type), boff_codings)) obj.baseline_offset_pattern = {timing target}; end objs(i) = obj; end