function [savePath]=readAll(pathToFile, subject,number,windowEMG,windowEEG,shiftEMG,shiftEEG,maxFile,...
    threshold,pburgOrder,minEEGFreq,maxEEGFreq,pause,noLFsamples,EMGChannels,noSynergies)

    %fprintf('start read %s%i %s\n',subject,number,datestr(datetime('now')));
    savePath=strcat(pathToFile,...
        sprintf('../matlabData/%s%i%imsWindowEMG%isWindowEEG%imsShiftEMG%imsShiftEEGFreq%ito%iPause%ipBurg%i.mat',...
        subject,number,windowEMG*1000,windowEEG,shiftEMG*1000,shiftEEG*1000,minEEGFreq,maxEEGFreq,pause,pburgOrder));
    
    %only create file if it doesn't exist yet
    if exist(savePath, 'file') ~= 2
        fprintf(strcat(savePath,' not existing; creating\n'));
        trainingDataEEGcell=cell(maxFile,1);
        trainingDataEEGlfCell=cell(maxFile,1);
        trainingDataEMGcell=cell(maxFile,1);
        classesCell=cell(maxFile,1);
        kin=cell([maxFile,1]);

        for i=1:maxFile
            [sig, stat, params] = load_bcidat(strcat(pathToFile,...
                sprintf('%s/%s_B100%i/%s_B1S00%iR0%i.dat',subject,subject,...
                number,subject,number,i)));
            tmpKin=csvread(strcat(pathToFile,...
                sprintf('kin/%s_B1S00%iR0%i.txt',subject,number,i)),1,0);
            [trainingDataEEGcell{i},trainingDataEEGlfCell{i},...
                trainingDataEMGcell{i},kin{i}]=generateTrainingData(sig,...
                tmpKin(:,1:4),windowEMG,windowEEG,shiftEMG,shiftEEG,params,pburgOrder,...
                minEEGFreq,maxEEGFreq,noLFsamples,EMGChannels);
            classesCell{i}=stat.StimulusCode;
            %fprintf('%ith file processed\n',i)
        end
        bci_sf=params.SamplingRate.NumericValue;

        clear sig

        trainingDataEEG=cell2mat(trainingDataEEGcell);
        trainingDataEEGlf=cell2mat(trainingDataEEGlfCell);
        trainingDataEMG=cell2mat(trainingDataEMGcell);
        classesMat=cell2mat(classesCell);
        kinMat=cell2mat(kin);
        clear trainingDataEEGcell trainingDataEMGcell classesCell kin

        classificationWithPause=classifyAccordingToEMG(size(...
            trainingDataEEG,1), trainingDataEMG,classesMat,shiftEMG,...
            bci_sf,threshold,pause);
        clear classesMat

        smoothClassificationEMG=zeros(size(classificationWithPause));
        for i=1:size(classificationWithPause,1)
            smoothClassificationEMG(i)=round(mode(classificationWithPause(...
                max(i-fix(bci_sf/1000),1):min(i+fix(bci_sf/1000),end))));       
        end

        clear classificationWithPause
        
        smoothClassificationEEG=zeros([size(trainingDataEEG,1),1]);
        for i=1:size(smoothClassificationEEG,1)
            smoothClassificationEEG(i)=mode(smoothClassificationEMG(fix(round(shiftEEG/shiftEMG*(i-1))+1):fix(round(shiftEEG/shiftEMG*i))));       
        end

        trainingDataEEG=trainingDataEEG(smoothClassificationEEG~=-1,:,:);
        trainingDataEEGlf=trainingDataEEGlf(smoothClassificationEEG~=-1,:,:);
        trainingDataEMG=trainingDataEMG(smoothClassificationEMG~=-1,:);
        classificationEMG=smoothClassificationEMG(smoothClassificationEMG~=-1);
        classificationEEG=smoothClassificationEEG(smoothClassificationEEG~=-1);
        kinematics=kinMat(smoothClassificationEMG~=-1,:);
        ae=trainAutoencoder(trainingDataEMG',noSynergies,'ShowProgressWindow',false);        
        synergiesAutoenc=encode(ae,trainingDataEMG')';
        COEFF=pca(trainingDataEMG,'Centered',false);
        synergiesPCA=trainingDataEMG/COEFF(:,1:4)';
        [~,H]=nnmf(trainingDataEMG,noSynergies);
        synergiesNNMF=trainingDataEMG*H';

        clear smoothClassification i
        save(savePath,'trainingDataEEG','trainingDataEEGlf','trainingDataEMG',...
            'classificationEMG','classificiationEEG','kinematics','synergiesAutoenc','synergiesPCA',...
            'synergiesNNMF','-v7.3');


        %fprintf('finished reading %s%i %s\n',subject,number,datestr(datetime('now')));
    end
end
