extrctresp.m 1.5 KB

12345678910111213141516171819202122232425262728293031
  1. %% Function: extract deviant responses following a standard response and standard responses preceding a deviant response from sorted sorted response blocks
  2. function [dev_as,std_bd,nResp] = extrctresp(dev_all,std_all,seq)
  3. % calculate number of stimulations, points per sample & number of deviants
  4. nTrials = size(seq,2);
  5. pSmpl = size(dev_all,1);
  6. nDev = sum(seq);
  7. % create deviant and standard sequence
  8. seq_dev = logical(seq);
  9. seq_std = ~seq;
  10. % 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
  11. seq_std_bd = logical([seq_dev(2:nTrials),zeros(1,1)]); % shift original dev sequences by 1 point (forwards)
  12. seq_std_bd = seq_std_bd(seq_std); % index into shifted deviant sequences with original std sequences to obtain stds before devs
  13. seq_dev_as = logical([zeros(1,1),seq_std(1:nTrials-1)]); % shift original std sequences by 1 point (backwards)
  14. seq_dev_as = seq_dev_as(seq_dev); % index into shifted standard sequences with original dev sequences to obtain dev after stds
  15. % apply newly generated sequences on dev and std datasets
  16. std_bd = std_all(:,seq_std_bd);
  17. dev_as = dev_all(:,seq_dev_as);
  18. % to have a constant array-size across recordings, add columns of zeros up to original
  19. % dev-array size (= maximum number of responses)
  20. nResp = size(std_bd,2); % number of above extracted responses
  21. std_bd = [std_bd,zeros(pSmpl,nDev-nResp)];
  22. dev_as = [dev_as,zeros(pSmpl,nDev-nResp)];