DD_UniteDatapoints.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. %% load data from windows directory and save them in matlab variableOm
  2. % read data
  3. projectdir_stim = '';
  4. projectdir_rec = '';
  5. mFileName = 'DD_Data_OR_25ms.mat';
  6. mVarName = 'Data_OR_Low_HighOm';
  7. dinfo_stim = dir(fullfile(projectdir_stim));
  8. dinfo_stim([dinfo_stim.isdir]) = []; %get rid of all directories including . and ..
  9. dinfo_rec = dir(fullfile(projectdir_rec));
  10. dinfo_rec([dinfo_rec.isdir]) = [];
  11. nfiles = length(dinfo_stim);
  12. Data_OR_Low_HighOm = [];
  13. for j = 1:nfiles
  14. %% process stimulation data
  15. filename_stim = fullfile(projectdir_stim, dinfo_stim(j).name);
  16. filedate_stim = dinfo_stim(j).datenum;
  17. filedate_stim = datetime(filedate_stim,'ConvertFrom','datenum','Format','yyyyMMdd','Locale',"de_DE");
  18. fid = fopen(filename_stim, 'r');
  19. Parameters = fread(fid,60,'float32')';
  20. sf = Parameters(4);
  21. fdown = Parameters(17);
  22. FileIndex = Parameters(2);
  23. nstims = Parameters(12);
  24. blocklength = Parameters(44);
  25. % AB locked runs
  26. if FileIndex==8
  27. seq = fread(fid,nstims,'float32')';
  28. fclose(fid);
  29. end
  30. % Std/Dev only runs & other Oddball runs
  31. if FileIndex==6||FileIndex==7||FileIndex==9||FileIndex==10||FileIndex==11||FileIndex==12
  32. seq = fread(fid,nstims,'float32')';
  33. fclose(fid);
  34. end
  35. % MR runs
  36. if FileIndex==13
  37. seq = fread(fid,nstims,'float32')';
  38. seq_MR = fread(fid,nstims,'float32')';
  39. fclose(fid);
  40. end
  41. %% process recording data
  42. 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)
  43. hdr = ft_read_header(filename_rec);
  44. trig = ft_read_event(filename_rec);
  45. dat = ft_read_data(filename_rec);
  46. %% Save files
  47. File_stim = convertCharsToStrings(filename_stim);
  48. File_rec = convertCharsToStrings(filename_rec);
  49. File_date = filedate_stim;
  50. switch FileIndex
  51. case {1,2,3,4,5,6,7,8,9,10,11,12}
  52. Data_temp = {File_stim,Parameters,seq,File_rec,hdr,trig,dat,File_date};
  53. case 13
  54. Data_temp = {File_stim,Parameters,seq_MR,File_rec,hdr,trig,dat,File_date};
  55. case 14
  56. Data_temp = {File_stim,Parameters,av_unit_NF,av_unit,File_rec,hrd,trig,dat,File_date};
  57. end
  58. Data_OR_Low_HighOm = [Data_OR_Low_HighOm;Data_temp];
  59. end
  60. if isfile(mFileName)==0
  61. save(mFileName,mVarName,'-v7.3')
  62. else
  63. save(mFileName,mVarName,'-append')
  64. end
  65. beep