clear
clc

d=dir('*.csv')

%get each subject's data by subject id matrix(:, 2), then create new .csv
%with just the matrix from 1 subject



for i = 1:length({d.name})
    %format longg
    dat = d.name;
    opts = detectImportOptions(dat);
    opts = setvartype(opts,'condition','char')
    data = readtable(d(i).name,opts);

    
    
    dataSort = sortrows(data,2);
    %matrix sizes = 144x14

    frontInc = 1;
    backInc = 192;
    numSubs = numel(unique(dataSort(:,2)))
    
    for k = 1:numSubs
        newMat = dataSort(frontInc:backInc,:)
        writetable(newMat, strcat('sub', num2str(k), '.csv'))
        frontInc = frontInc + 192
        backInc = backInc + 192
    end

end