maketrials_eyetracking_V1.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. function [data_epoch] = maketrials_eyetracking_V1(cfg)
  2. %First input = data after importeyes; second input = trigger
  3. mdat=cfg.data;
  4. alltriggers= cfg.triggers;
  5. pretim = cfg.prestim;
  6. posttim = cfg.poststim;
  7. tmp=mdat.evt;
  8. evt=zeros(length(tmp),1);
  9. for i=1:length(tmp)
  10. if isempty(str2num(tmp{i}))
  11. evt(i)=NaN;
  12. else
  13. evt(i)=str2num(tmp{i});
  14. end
  15. end
  16. tim=mdat.evT;
  17. tcounter=1;
  18. % Make epochs
  19. for tri=1:length(alltriggers)
  20. trigger=alltriggers(tri);
  21. found=find(evt==trigger);
  22. % tim(found(ttt))
  23. for ttt = 1:length(found)
  24. onset= tim(found(ttt));
  25. [ d1, ix1 ] = min( abs( mdat.time-(onset-pretim) ) );
  26. [ d1, ix2 ] = min( abs( mdat.time-(onset+posttim) ) );
  27. oritime_nosort(tcounter,:)= mdat.time(ix1:ix2) ;%original time
  28. eyedat_nosort(tcounter,1,:)= mdat.x(ix1:ix2); %x
  29. eyedat_nosort(tcounter,2,:)= mdat.y(ix1:ix2); %y
  30. eyedat_nosort(tcounter,3,:)= mdat.p(ix1:ix2); %p
  31. trigger_onset_nosort(tcounter)=(trigger);
  32. tcounter=tcounter+1;
  33. end
  34. end
  35. %sorting everything by time
  36. [A I]= sort(oritime_nosort(:,1))
  37. data_epoch.originaltime=[]
  38. data_epoch.eyedat=[]
  39. data_epoch.trigger_onset=[]
  40. data_epoch.eyedat= eyedat_nosort(I,:,:);
  41. data_epoch.originaltime= oritime_nosort(I,:);
  42. data_epoch.trigger_onset=trigger_onset_nosort(I);
  43. data_epoch.channel=['x';'y';'p';];
  44. %make the time for the epoch
  45. t1=length(-pretim:posttim)-1
  46. t2=size(data_epoch.eyedat,3)-1
  47. spac=t1/t2
  48. data_epoch.time=-pretim:spac:posttim;
  49. end