12345678910111213141516171819202122232425262728293031 |
- %% Function: extract deviant responses following a standard response and standard responses preceding a deviant response from sorted sorted response blocks
- function [dev_as,std_bd,nResp] = extrctresp(dev_all,std_all,seq)
- % calculate number of stimulations, points per sample & number of deviants
- nTrials = size(seq,2);
- pSmpl = size(dev_all,1);
- nDev = sum(seq);
- % create deviant and standard sequence
- seq_dev = logical(seq);
- seq_std = ~seq;
- % shift dev and std sequence by one point and index into it with original std and dev sequence to obtain stds before devs and devs after stds
- seq_std_bd = logical([seq_dev(2:nTrials),zeros(1,1)]); % shift original dev sequences by 1 point (forwards)
- seq_std_bd = seq_std_bd(seq_std); % index into shifted deviant sequences with original std sequences to obtain stds before devs
- seq_dev_as = logical([zeros(1,1),seq_std(1:nTrials-1)]); % shift original std sequences by 1 point (backwards)
- seq_dev_as = seq_dev_as(seq_dev); % index into shifted standard sequences with original dev sequences to obtain dev after stds
- % apply newly generated sequences on dev and std datasets
- std_bd = std_all(:,seq_std_bd);
- dev_as = dev_all(:,seq_dev_as);
- % to have a constant array-size across recordings, add columns of zeros up to original
- % dev-array size (= maximum number of responses)
- nResp = size(std_bd,2); % number of above extracted responses
- std_bd = [std_bd,zeros(pSmpl,nDev-nResp)];
- dev_as = [dev_as,zeros(pSmpl,nDev-nResp)];
-
|