%% load data from windows directory and save them in matlab variableOm % read data projectdir_stim = ''; projectdir_rec = ''; mFileName = 'DD_Data_OR_25ms.mat'; mVarName = 'Data_OR_Low_HighOm'; dinfo_stim = dir(fullfile(projectdir_stim)); dinfo_stim([dinfo_stim.isdir]) = []; %get rid of all directories including . and .. dinfo_rec = dir(fullfile(projectdir_rec)); dinfo_rec([dinfo_rec.isdir]) = []; nfiles = length(dinfo_stim); Data_OR_Low_HighOm = []; for j = 1:nfiles %% process stimulation data filename_stim = fullfile(projectdir_stim, dinfo_stim(j).name); filedate_stim = dinfo_stim(j).datenum; filedate_stim = datetime(filedate_stim,'ConvertFrom','datenum','Format','yyyyMMdd','Locale',"de_DE"); fid = fopen(filename_stim, 'r'); Parameters = fread(fid,60,'float32')'; sf = Parameters(4); fdown = Parameters(17); FileIndex = Parameters(2); nstims = Parameters(12); blocklength = Parameters(44); % AB locked runs if FileIndex==8 seq = fread(fid,nstims,'float32')'; fclose(fid); end % Std/Dev only runs & other Oddball runs if FileIndex==6||FileIndex==7||FileIndex==9||FileIndex==10||FileIndex==11||FileIndex==12 seq = fread(fid,nstims,'float32')'; fclose(fid); end % MR runs if FileIndex==13 seq = fread(fid,nstims,'float32')'; seq_MR = fread(fid,nstims,'float32')'; fclose(fid); end %% process recording data filename_rec = fullfile(projectdir_rec, dinfo_rec(3*(j-1)+1).name); % ATTENTION: check again when more files are available ... get name of the .eeg file (should always be the first of the three files per recording) hdr = ft_read_header(filename_rec); trig = ft_read_event(filename_rec); dat = ft_read_data(filename_rec); %% Save files File_stim = convertCharsToStrings(filename_stim); File_rec = convertCharsToStrings(filename_rec); File_date = filedate_stim; switch FileIndex case {1,2,3,4,5,6,7,8,9,10,11,12} Data_temp = {File_stim,Parameters,seq,File_rec,hdr,trig,dat,File_date}; case 13 Data_temp = {File_stim,Parameters,seq_MR,File_rec,hdr,trig,dat,File_date}; case 14 Data_temp = {File_stim,Parameters,av_unit_NF,av_unit,File_rec,hrd,trig,dat,File_date}; end Data_OR_Low_HighOm = [Data_OR_Low_HighOm;Data_temp]; end if isfile(mFileName)==0 save(mFileName,mVarName,'-v7.3') else save(mFileName,mVarName,'-append') end beep