subsampleOm.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function [outDev,outStd,nTrialsDev,nTrialsStd] = subsampleOm(inDev,inStd,seqAcc,nTrialsAcc)
  2. %SUBSAMPLE Extracts deviants after standards and standards before deviants
  3. % Detailed explanation goes here
  4. % define some variables
  5. pSmpl = size(inDev,1);
  6. nTrials = size(inDev,2)*0.2;
  7. nBlcks = size(inDev,3);
  8. nFiles = size(inDev,4);
  9. nFilt = size(inDev,5);
  10. % perform the subsampling
  11. nTrialsDev = zeros(nBlcks,nFiles); % preallocate
  12. nTrialsStd = zeros(nBlcks,nFiles); % preallocate
  13. outDev = zeros(pSmpl,nTrials,nBlcks,nFiles,nFilt); % preallocate
  14. outStd = zeros(pSmpl,nTrials,nBlcks,nFiles,nFilt); % preallocate
  15. for f = 1:nFiles
  16. for b = 1:nBlcks
  17. % create sequences
  18. seqDev = logical(seqAcc(1:nTrialsAcc(b,f),b,f));
  19. seqStd = ~seqAcc(1:nTrialsAcc(b,f),b,f);
  20. % 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
  21. seqDev_as = logical([zeros(1,1);seqStd(1:nTrialsAcc(b,f)-1)]); % shift original std sequences by 1 point (backwards)
  22. seqDev_as = seqDev_as(seqDev); % index into shifted standard sequences with original dev sequences to obtain dev after stds
  23. seqStd_ad = logical([zeros(1,1);seqDev(1:nTrialsAcc(b,f)-1)]); % shift original dev sequences by 1 point (backwards)
  24. seqStd_ad = seqStd_ad(seqStd); % index into shifted deviant sequences with original std sequences to obtain stds after devs
  25. nTrialsDev(b,f) = sum(seqDev_as);
  26. nTrialsStd(b,f) = sum(seqStd_ad);
  27. % apply newly generated sequences on dev and std datasets
  28. outDev(:,1:nTrialsDev(b,f),b,f,:) = inDev(:,seqDev_as,b,f,:);
  29. outStd(:,1:nTrialsStd(b,f),b,f,:) = inStd(:,seqStd_ad,b,f,:);
  30. end
  31. end
  32. end