RS_UniteDatapoints.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. %% load data from windows directory and save them in matlab variable
  2. % read data
  3. projectdir_stim = '';
  4. projectdir_rec = '';
  5. mFileName = 'RS_Data_50ms.mat';
  6. mVarName = 'Data_High';
  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_High = [];
  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 OR 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,File_rec,hdr,trig,dat,File_date};
  57. end
  58. Data_High = [Data_High;Data_temp];
  59. end
  60. if isfile(mFileName)==0
  61. save(mFileName,mVarName,'-v7.3')
  62. else
  63. save(mFileName,mVarName,'-append')
  64. end