subsample.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. function [outDev,outStd,nTrialsSub] = subsample(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. nTrialsSub = zeros(nBlcks,nFiles); % preallocate
  12. outDev = zeros(pSmpl,nTrials,nBlcks,nFiles,nFilt); % preallocate
  13. outStd = zeros(pSmpl,nTrials,nBlcks,nFiles,nFilt); % preallocate
  14. for f = 1:nFiles
  15. for b = 1:nBlcks
  16. % create sequences
  17. seqDev = logical(seqAcc(1:nTrialsAcc(b,f),b,f));
  18. seqStd = ~seqAcc(1:nTrialsAcc(b,f),b,f);
  19. % 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
  20. seqDev_as = logical([zeros(1,1);seqStd(1:nTrialsAcc(b,f)-1)]); % shift original std sequences by 1 point (backwards)
  21. seqDev_as = seqDev_as(seqDev); % index into shifted standard sequences with original dev sequences to obtain dev after stds
  22. seqStd_bd = logical([seqDev(2:nTrialsAcc(b,f));zeros(1,1)]); % shift original dev sequences by 1 point (forwards)
  23. seqStd_bd = seqStd_bd(seqStd); % index into shifted deviant sequences with original std sequences to obtain stds before devs
  24. nTrialsSub(b,f) = sum(seqStd_bd);
  25. % apply newly generated sequences on dev and std datasets
  26. outDev(:,1:nTrialsSub(b,f),b,f,:) = inDev(:,seqDev_as,b,f,:);
  27. outStd(:,1:nTrialsSub(b,f),b,f,:) = inStd(:,seqStd_bd,b,f,:);
  28. end
  29. end
  30. end