%% create artificial datasets and sequences data_dev = [10,3,3,1;1,3,1,3;3,3,3,3]'; data_std = [2,11,2,2,4,2,4,2;2,2,4,2,4,2,2,2;2,4,2,2,4,4,4,2]'; n_files = size(data_dev,2); n_dev = size(data_dev,1); n_std = size(data_std,1); n_stims = n_dev+n_std; seq = [1,1,0,1,1,1,0,1,1,0,0,1;0,1,1,1,0,0,1,1,0,1,1,1;1,1,0,1,1,1,0,1,0,1,0,1]'; seqStd = logical(seq); seqDev = ~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 seqStd_ad = logical([zeros(1,n_files);seqDev(1:n_stims-1,:)]); % shift original dev sequences by 1 point (backwards) seqStd_ad = reshape(seqStd_ad(seqStd),n_std,n_files); % index into shifted deviant sequences with original standard sequences to obtain stds after devs seqDev_as = logical([zeros(1,n_files);seqStd(1:n_stims-1,:)]); % shift original std sequences by 1 point (backwards) seqDev_as = reshape(seqDev_as(seqDev),n_dev,n_files); % index into shifted standard sequences with original dev sequences to obtain dev after stds %% apply newly generated sequences on dev and std datasets sample_std = cell(1,n_files); sample_dev = cell(1,n_files); for j = 1:n_files sample_std{1,j} = data_std(seqStd_ad(:,j),j); sample_dev{1,j} = data_dev(seqDev_as(:,j),j); end %% same approach with only one std/dev dataset data_dev = [10,3,3,1]; data_std = [2,11,2,2,4,2,4,2]; seq = [1,1,0,1,1,1,0,1,1,0,0,1]; seq_std = logical(seq); seq_dev = ~seq; seq_std_bd_temp = logical([seq_dev(2:end),zeros(1,1)]); seqStd_ad = seq_std_bd_temp(seq_std); seq_dev_as_temp = logical([zeros(1,1),seq_std(1:end-1)]); seqDev_as = seq_dev_as_temp(seq_dev); sample_std = data_std(seqStd_ad) sample_dev = data_dev(seqDev_as) bla = 1;