% make sure the onset table is available in variable ot !! % configuration conds = {'INST', 'CUE1', 'CUE2'}; condcol = [255, 0, 0; 0, 255, 0; 0, 0, 255]; % find unique subject IDs subjid = unique(ot(:, 1)); % for each subject ID for sc = 1:numel(subjid) % get this subject's sub-table sot = ot(ot(:, 1) == subjid(sc), :); % set NaNs to zero (for now) sot(isnan(sot)) = 0; % get onsets and offsets of any trial onsets = sum(sot(:, 2:2+numel(conds)-1), 2); % get table with NaNs (again) for condition detection sot = ot(ot(:, 1) == subjid(sc), :); % find run-separators runseps = 1 + [0; find(diff(onsets) < 0)]; runseps(end+1) = numel(onsets) + 1; % for each run for rc = 1:numel(runseps)-1 % get part of table we need rot = sot(runseps(rc):runseps(rc+1)-1, 2:end); % create new PRT prt = xff('new:prt'); % for each condition for cc = 1:numel(conds) % add to PRT prt.AddCond(conds{cc}, rot(~isnan(rot(:, cc)), [cc, cc + numel(conds)]), condcol(cc, :)); end % save PRT prt.SaveAs(sprintf('%d_%d.prt', subjid(sc), rc)); % clear object prt.ClearObject; end end