function [outDev,outStd,nTrialsDev,nTrialsStd] = subsampleOm(inDev,inStd,seqAcc,nTrialsAcc) %SUBSAMPLE Extracts deviants after standards and standards before deviants % Detailed explanation goes here % define some variables pSmpl = size(inDev,1); nTrials = size(inDev,2)*0.2; nBlcks = size(inDev,3); nFiles = size(inDev,4); nFilt = size(inDev,5); % perform the subsampling nTrialsDev = zeros(nBlcks,nFiles); % preallocate nTrialsStd = zeros(nBlcks,nFiles); % preallocate outDev = zeros(pSmpl,nTrials,nBlcks,nFiles,nFilt); % preallocate outStd = zeros(pSmpl,nTrials,nBlcks,nFiles,nFilt); % preallocate for f = 1:nFiles for b = 1:nBlcks % create sequences seqDev = logical(seqAcc(1:nTrialsAcc(b,f),b,f)); seqStd = ~seqAcc(1:nTrialsAcc(b,f),b,f); % 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 seqDev_as = logical([zeros(1,1);seqStd(1:nTrialsAcc(b,f)-1)]); % shift original std sequences by 1 point (backwards) seqDev_as = seqDev_as(seqDev); % index into shifted standard sequences with original dev sequences to obtain dev after stds seqStd_ad = logical([zeros(1,1);seqDev(1:nTrialsAcc(b,f)-1)]); % shift original dev sequences by 1 point (backwards) seqStd_ad = seqStd_ad(seqStd); % index into shifted deviant sequences with original std sequences to obtain stds after devs nTrialsDev(b,f) = sum(seqDev_as); nTrialsStd(b,f) = sum(seqStd_ad); % apply newly generated sequences on dev and std datasets outDev(:,1:nTrialsDev(b,f),b,f,:) = inDev(:,seqDev_as,b,f,:); outStd(:,1:nTrialsStd(b,f),b,f,:) = inStd(:,seqStd_ad,b,f,:); end end end