getEyeTracks.m 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. function [eyedata] = getEyeTracks(subjdata,sesn,timeStartAlgn,timeEndAlgn)
  2. if nargin < 4
  3. if nargin < 3
  4. if nargin < 2
  5. if nargin< 1
  6. error('Provide subject data.');
  7. end
  8. sesn='all';
  9. end
  10. timeStartAlgn='offer1';
  11. end
  12. timeEndAlgn='choicemade';
  13. end
  14. if strcmpi(sesn,'all')
  15. sesn=1:length(subjdata);
  16. end
  17. for sn=sesn
  18. for tr=1:length(subjdata{sn}.timings)
  19. curroff1ref=round(subjdata{sn}.timings(tr).appearOffer1Time);
  20. if strcmpi(timeStartAlgn,'offer1')
  21. timeStartBin=0;
  22. elseif strcmpi(timeStartAlgn,'delay1')
  23. timeStartBin=round(subjdata{sn}.timings(tr).disappearOffer1Time)-curroff1ref;
  24. elseif strcmpi(timeStartAlgn,'offer2')
  25. timeStartBin=round(subjdata{sn}.timings(tr).appearOffer2Time)-curroff1ref;
  26. elseif strcmpi(timeStartAlgn,'delay2')
  27. timeStartBin=round(subjdata{sn}.timings(tr).disappearOffer2Time)-curroff1ref;
  28. elseif strcmpi(timeStartAlgn,'fixdot')
  29. timeStartBin=round(subjdata{sn}.timings(tr).appearFixDotTime)-curroff1ref;
  30. elseif strcmpi(timeStartAlgn,'choicego')
  31. timeStartBin=round(subjdata{sn}.timings(tr).choiceGoTime)-curroff1ref;
  32. elseif strcmpi(timeStartAlgn,'feedback')
  33. timeStartBin=round(subjdata{sn}.timings(tr).feedbackTime)-curroff1ref;
  34. elseif strcmpi(timeStartAlgn,'startfix')
  35. timeStartBin=round(subjdata{sn}.timings(tr).fixStartFixnDotTime)-curroff1ref;
  36. elseif strcmpi(timeStartAlgn,'choicemade')
  37. timeStartBin=round(subjdata{sn}.timings(tr).choiceMadeTime)-curroff1ref;
  38. elseif strcmpi(timeStartAlgn,'choicesacc')
  39. timeStartBin=round(min([subjdata{sn}.timings(tr).fixStartRightOfferTime subjdata{sn}.timings(tr).fixStartLeftOfferTime]))-curroff1ref;
  40. elseif strcmpi(timeStartAlgn,'preoffer1')
  41. timeStartBin=-3000;
  42. end
  43. if strcmpi(timeEndAlgn,'offer1')
  44. timeEndBin=0;
  45. elseif strcmpi(timeEndAlgn,'delay1')
  46. timeEndBin=round(subjdata{sn}.timings(tr).disappearOffer1Time)-curroff1ref;
  47. elseif strcmpi(timeEndAlgn,'offer2')
  48. timeEndBin=round(subjdata{sn}.timings(tr).appearOffer2Time)-curroff1ref;
  49. elseif strcmpi(timeEndAlgn,'delay2')
  50. timeEndBin=round(subjdata{sn}.timings(tr).disappearOffer2Time)-curroff1ref;
  51. elseif strcmpi(timeEndAlgn,'fixdot')
  52. timeEndBin=round(subjdata{sn}.timings(tr).appearFixDotTime)-curroff1ref;
  53. elseif strcmpi(timeEndAlgn,'choicego')
  54. timeEndBin=round(subjdata{sn}.timings(tr).choiceGoTime)-curroff1ref;
  55. elseif strcmpi(timeEndAlgn,'feedback')
  56. timeEndBin=round(subjdata{sn}.timings(tr).feedbackTime)-curroff1ref;
  57. elseif strcmpi(timeEndAlgn,'startfix')
  58. timeEndBin=round(subjdata{sn}.timings(tr).fixStartFixnDotTime)-curroff1ref;
  59. elseif strcmpi(timeEndAlgn,'choicemade')
  60. timeEndBin=round(subjdata{sn}.timings(tr).choiceMadeTime)-curroff1ref;
  61. elseif strcmpi(timeEndAlgn,'choicesacc')
  62. timeEndBin=round(min([subjdata{sn}.timings(tr).fixStartRightOfferTime subjdata{sn}.timings(tr).fixStartLeftOfferTime]))-curroff1ref;
  63. elseif strcmpi(timeEndAlgn,'trialend')
  64. timeEndBin=7000;
  65. end
  66. currsn_eyedata_str{tr}.posX(1:(timeEndBin-timeStartBin))=subjdata{sn}.eyetracks.posX(tr,(timeStartBin+1:timeEndBin)+3000);
  67. currsn_eyedata_str{tr}.posY(1:(timeEndBin-timeStartBin))=subjdata{sn}.eyetracks.posY(tr,(timeStartBin+1:timeEndBin)+3000);
  68. end
  69. maxntp=max(arrayfun(@(tr) size(currsn_eyedata_str{tr}.posX,2),1:length(subjdata{sn}.timings)));
  70. eyedata_str{sn}.posX=nan(length(subjdata{sn}.timings),maxntp);
  71. eyedata_str{sn}.posY=nan(length(subjdata{sn}.timings),maxntp);
  72. for tr=1:length(subjdata{sn}.timings)
  73. eyedata_str{sn}.posX(tr,1:size(currsn_eyedata_str{tr}.posX,2))=currsn_eyedata_str{tr}.posX;
  74. eyedata_str{sn}.posY(tr,1:size(currsn_eyedata_str{tr}.posY,2))=currsn_eyedata_str{tr}.posY;
  75. end
  76. clearvars currsn_eyedata_str
  77. end
  78. maxlen=max(arrayfun(@(xx) size(eyedata_str{xx}.posX,2),sesn));
  79. eyedata_str{sn}.posX(:,maxlen+1:end)=[];
  80. eyedata.posX=[]; eyedata.posY=[];
  81. for sn=sesn
  82. eyedata.posX=cat(1,eyedata.posX,[eyedata_str{sn}.posX nan(size(eyedata_str{sn}.posX,1), maxlen-size(eyedata_str{sn}.posX,2))]);
  83. eyedata.posY=cat(1,eyedata.posY,[eyedata_str{sn}.posY nan(size(eyedata_str{sn}.posY,1), maxlen-size(eyedata_str{sn}.posY,2))]);
  84. end
  85. end