getSpikeSequences.m 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. function [spkdata] = getSpikeSequences(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. spkdata_str{sesn}.spikeseqs=[];
  18. for sn=sesn
  19. for tr=1:size(subjdata{sn}.spikeseqs,1)
  20. curroff1ref=round(subjdata{sn}.timings(tr).appearOffer1Time);
  21. if strcmpi(timeStartAlgn,'offer1')
  22. timeStartBin=0;
  23. elseif strcmpi(timeStartAlgn,'delay1')
  24. timeStartBin=round(subjdata{sn}.timings(tr).disappearOffer1Time)-curroff1ref;
  25. elseif strcmpi(timeStartAlgn,'offer2')
  26. timeStartBin=round(subjdata{sn}.timings(tr).appearOffer2Time)-curroff1ref;
  27. elseif strcmpi(timeStartAlgn,'delay2')
  28. timeStartBin=round(subjdata{sn}.timings(tr).disappearOffer2Time)-curroff1ref;
  29. elseif strcmpi(timeStartAlgn,'fixdot')
  30. timeStartBin=round(subjdata{sn}.timings(tr).appearFixDotTime)-curroff1ref;
  31. elseif strcmpi(timeStartAlgn,'choicego')
  32. timeStartBin=round(subjdata{sn}.timings(tr).choiceGoTime)-curroff1ref;
  33. elseif strcmpi(timeStartAlgn,'feedback')
  34. timeStartBin=round(subjdata{sn}.timings(tr).feedbackTime)-curroff1ref;
  35. elseif strcmpi(timeStartAlgn,'startfix')
  36. timeStartBin=round(subjdata{sn}.timings(tr).fixStartFixnDotTime)-curroff1ref;
  37. elseif strcmpi(timeStartAlgn,'choicemade')
  38. timeStartBin=round(subjdata{sn}.timings(tr).choiceMadeTime)-curroff1ref;
  39. elseif strcmpi(timeStartAlgn,'choicesacc')
  40. timeStartBin=round(min([subjdata{sn}.timings(tr).fixStartRightOfferTime subjdata{sn}.timings(tr).fixStartLeftOfferTime]))-curroff1ref;
  41. elseif strcmpi(timeStartAlgn,'preoffer1')
  42. timeStartBin=-3000;
  43. end
  44. if strcmpi(timeEndAlgn,'offer1')
  45. timeEndBin=0;
  46. elseif strcmpi(timeEndAlgn,'delay1')
  47. timeEndBin=round(subjdata{sn}.timings(tr).disappearOffer1Time)-curroff1ref;
  48. elseif strcmpi(timeEndAlgn,'offer2')
  49. timeEndBin=round(subjdata{sn}.timings(tr).appearOffer2Time)-curroff1ref;
  50. elseif strcmpi(timeEndAlgn,'delay2')
  51. timeEndBin=round(subjdata{sn}.timings(tr).disappearOffer2Time)-curroff1ref;
  52. elseif strcmpi(timeEndAlgn,'fixdot')
  53. timeEndBin=round(subjdata{sn}.timings(tr).appearFixDotTime)-curroff1ref;
  54. elseif strcmpi(timeEndAlgn,'choicego')
  55. timeEndBin=round(subjdata{sn}.timings(tr).choiceGoTime)-curroff1ref;
  56. elseif strcmpi(timeEndAlgn,'feedback')
  57. timeEndBin=round(subjdata{sn}.timings(tr).feedbackTime)-curroff1ref;
  58. elseif strcmpi(timeEndAlgn,'startfix')
  59. timeEndBin=round(subjdata{sn}.timings(tr).fixStartFixnDotTime)-curroff1ref;
  60. elseif strcmpi(timeEndAlgn,'choicemade')
  61. timeEndBin=round(subjdata{sn}.timings(tr).choiceMadeTime)-curroff1ref;
  62. elseif strcmpi(timeEndAlgn,'choicesacc')
  63. timeEndBin=round(min([subjdata{sn}.timings(tr).fixStartRightOfferTime subjdata{sn}.timings(tr).fixStartLeftOfferTime]))-curroff1ref;
  64. elseif strcmpi(timeEndAlgn,'trialend')
  65. timeEndBin=7000;
  66. end
  67. currsnspksq{tr}.currtrspksq(:,1:(timeEndBin-timeStartBin))=subjdata{sn}.spikeseqs(tr,:,(timeStartBin+1:timeEndBin)+3000);
  68. end
  69. maxntp=max(arrayfun(@(tr) size(currsnspksq{tr}.currtrspksq,2),1:size(currsnspksq,2)));
  70. spkdata_str{sn}.spikeseqs=nan(size(subjdata{sn}.spikeseqs,1),size(subjdata{sn}.spikeseqs,2),maxntp);
  71. for tr=1:size(subjdata{sn}.spikeseqs,1)
  72. spkdata_str{sn}.spikeseqs(tr,:,1:size(currsnspksq{tr}.currtrspksq,2))=currsnspksq{tr}.currtrspksq;
  73. end
  74. clearvars currsnspksq
  75. end
  76. maxntp=max(arrayfun(@(xx) size(spkdata_str{xx}.spikeseqs,3),sesn));
  77. spkdata.spikeseqs=[];
  78. for sn=sesn
  79. spkdata.spikeseqs=cat(1,spkdata.spikeseqs,cat(3,spkdata_str{sn}.spikeseqs,...
  80. nan([size(spkdata_str{sn}.spikeseqs,1:2), maxntp-size(spkdata_str{sn}.spikeseqs,3)])));
  81. end
  82. spkdata.starttime=timeStartAlgn;
  83. spkdata.endtime=timeEndAlgn;
  84. end