C_Figure3.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. clear all
  2. close all
  3. ColorsTask=[51/255 102/255 204/255,
  4. 153/255 204/255 51/255
  5. 255/255 153/255 51/255];
  6. TaskID=cat(1,ones(6,1),2*ones(6,1),3*ones(6,1));
  7. Table_all=[];
  8. for task=1:3
  9. if task==1
  10. load('RAW_DT5.mat')
  11. path='E:\Youna\Post-doc\MATLAB\Youna Matlab\DT Nex Files\RESULTdt.xls'; %excel file with windows etc
  12. [~,Session] = xlsread(path,'Windows','c21:c30');
  13. Rat={'YVG04' 'YVG05' 'YVG08' 'YVG10' 'YVG11' 'YVG12'};
  14. sesSel=[1 10];
  15. elseif task==2
  16. load('RAW_FR5.mat')
  17. path='E:\Youna\Post-doc\MATLAB\Youna Matlab\DT Nex Files\RESULTfr5.xls'; %excel file with windows etc
  18. [~,Session] = xlsread(path,'Windows','c20:c29');
  19. Rat={'YVU01' 'YVU02' 'YVU03' 'YVU04' 'YVU05' 'YVU06'};
  20. sesSel=[1 10];
  21. else
  22. load('RAW_FS5.mat')
  23. path='E:\Youna\Post-doc\MATLAB\Youna Matlab\DT Nex Files\RESULTfs5.xls'; %excel file with windows etc
  24. [~,Session] = xlsread(path,'Windows','c23:c29');
  25. Rat={'YVAF2', 'YVV08' 'YVV10' 'YVV11' 'YVV13' 'YVV14' };
  26. sesSel=[1 7];
  27. end
  28. clear RatName
  29. SessionName = {RAW.SessionName};
  30. for i=1:length(RAW) %loops through sessions
  31. RatName{i,1}=RAW(i).Einfo{1,1}(1:5);
  32. end
  33. for i=1:length(Session) %loops through sessions
  34. for y=1:length(Rat)% loop through rats
  35. ses=strcmp(Session(i),SessionName);
  36. rat=strcmp(Rat(y),RatName)';
  37. SesIndex=find(ses & rat);
  38. First_LP=[];
  39. Middle_LP=[];
  40. Last_LP=[];
  41. EvInd_LP=strcmp('LeverPress',RAW(SesIndex).Einfo(:,2));
  42. EvInd_LLP=strcmp('Last_LP',RAW(SesIndex).Einfo(:,2));
  43. if task<3
  44. EvInd_FLP=strcmp('First_LP',RAW(SesIndex).Einfo(:,2));
  45. EvInd_MLP=strcmp('Third_LP',RAW(SesIndex).Einfo(:,2));
  46. else
  47. EvInd_FLP=strcmp('First_LPcomp',RAW(SesIndex).Einfo(:,2));
  48. EvInd_MLP=strcmp('Intermediate_LP',RAW(SesIndex).Einfo(:,2));
  49. end
  50. First_LP=RAW(SesIndex).Erast{EvInd_FLP};
  51. Middle_LP=RAW(SesIndex).Erast{EvInd_MLP};
  52. Last_LP=RAW(SesIndex).Erast{EvInd_LLP};
  53. LeverPress=RAW(SesIndex).Erast{EvInd_LP};
  54. rat=strcmp(RAW(SesIndex).Einfo{1,1}(1:5),RatName);
  55. ratIndex=find(rat==1);
  56. FirstP_autocorr=MakePSRlever(LeverPress,First_LP,[0.001 6]);
  57. MiddleP_autocorr=MakePSRlever(LeverPress,Middle_LP,[-3 3]);
  58. LastP_autocorr=MakePSRlever(LeverPress,Last_LP,[-6 -0.001]);
  59. FirstP_autocorr(isnan(FirstP_autocorr)) = [];
  60. MiddleP_autocorr(isnan(MiddleP_autocorr)) = [];
  61. LastP_autocorr(isnan(LastP_autocorr)) = [];
  62. [value,edges]=histcounts(FirstP_autocorr,20);
  63. FirstP_HistVal{i,task}(y,:)=value;
  64. [value,edges]=histcounts(MiddleP_autocorr,20);
  65. MiddleP_HistVal{i,task}(y,:)=value;
  66. [value,edges]=histcounts(LastP_autocorr,20);
  67. LastP_HistVal{i,task}(y,:)=value;
  68. end
  69. end
  70. FirstP_XVal=linspace(0,5.7,20);
  71. MiddleP_XVal=linspace(-3,2.7,20);
  72. LastP_XVal=linspace(-5.7,0,20);
  73. Xaxis=[0 6;-3 3; -6 0];
  74. Yaxis=[0 30];
  75. xtitles={'time from LP1','time from ILP','time from LLP'};
  76. figure(2)
  77. for i=1:2 %loop thru first last session
  78. for ev=1:3 %loop thru event
  79. if ev==1
  80. Hist=FirstP_HistVal;
  81. Xval=FirstP_XVal;
  82. elseif ev==2
  83. Hist=MiddleP_HistVal;
  84. Xval=MiddleP_XVal;
  85. else
  86. Hist=LastP_HistVal;
  87. Xval=LastP_XVal;
  88. end
  89. Table{ev,i}{task}=Hist{sesSel(i),task};
  90. subplot(2,3,ev+3*(i-1))
  91. MeanRat_DistribF=nanmean(Hist{sesSel(i),task},1);
  92. steRat_DistribF=nansem(Hist{sesSel(i),task},1);
  93. ix=(Xval~=0);
  94. errorbar(Xval(ix),MeanRat_DistribF(ix),steRat_DistribF(ix),'-o','MarkerSize',6,'Color','b','MarkerFaceColor',ColorsTask(task,:),'MarkerEdgeColor','k','CapSize',0,'LineWidth',1);
  95. hold on
  96. for rat=1:6
  97. plot1=plot(Xval(ix),Hist{sesSel(i),task}(rat,ix),'color',ColorsTask(task,:),'LineWidth',1);
  98. plot1.Color(4) = 0.2;
  99. end
  100. xlabel(xtitles{ev});
  101. ylabel('Frequency');
  102. axis([Xaxis(ev,:),Yaxis]);
  103. set(gca, 'box', 'off')
  104. end
  105. end
  106. end
  107. %% statistics
  108. %make table
  109. rep=0;
  110. cond={'1st ses, ev1','1st ses, ev2','1st ses, ev3','last ses, ev1','last ses, ev2','last ses, ev3'};
  111. for session=1:2
  112. for ev=1:3
  113. rep=rep+1;
  114. Table_allTask=cat(1,Table{ev,session}{:});
  115. if ev==2
  116. ix=(MiddleP_XVal~=0);
  117. Table_Stat=cat(2,TaskID,Table_allTask(:,ix));
  118. tableSTAT=array2table(Table_Stat,'VariableNames',{'task','win1','win2','win3','win4','win5','win6','win7','win8','win9','win10','win12','win13','win14','win15','win16','win17','win18','win19','win20'});
  119. nbbin=[1:19];
  120. else
  121. Table_Stat=cat(2,TaskID,Table_allTask);
  122. tableSTAT=array2table(Table_Stat,'VariableNames',{'task','win1','win2','win3','win4','win5','win6','win7','win8','win9','win10','win11','win12','win13','win14','win15','win16','win17','win18','win19','win20'});
  123. nbbin=[1:20];
  124. end
  125. tableSTAT.task=categorical(tableSTAT.task);
  126. stat(rep).condition=cond{rep};
  127. rm_reg = fitrm(tableSTAT,'win1-win20~task','WithinDesign',nbbin');
  128. stat(rep).ranovatbl_event = ranova(rm_reg);
  129. stat(rep).Btw_ranovatbl_event = anova(rm_reg);
  130. stat(rep).posthoc = multcompare(rm_reg,'task');
  131. filename = 'ResultStat_behav.xlsx';
  132. writetable(stat(rep).ranovatbl_event,filename,'Sheet',rep,'Range','A1')
  133. writetable(stat(rep).Btw_ranovatbl_event,filename,'Sheet',rep,'Range','J1')
  134. writetable(stat(rep).posthoc,filename,'Sheet',rep,'Range','R1')
  135. end
  136. end