123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- clear all
- close all
- ColorsTask=[51/255 102/255 204/255,
- 153/255 204/255 51/255
- 255/255 153/255 51/255];
- TaskID=cat(1,ones(6,1),2*ones(6,1),3*ones(6,1));
- Table_all=[];
- for task=1:3
- if task==1
- load('RAW_DT5.mat')
- path='E:\Youna\Post-doc\MATLAB\Youna Matlab\DT Nex Files\RESULTdt.xls'; %excel file with windows etc
- [~,Session] = xlsread(path,'Windows','c21:c30');
- Rat={'YVG04' 'YVG05' 'YVG08' 'YVG10' 'YVG11' 'YVG12'};
- sesSel=[1 10];
- elseif task==2
- load('RAW_FR5.mat')
- path='E:\Youna\Post-doc\MATLAB\Youna Matlab\DT Nex Files\RESULTfr5.xls'; %excel file with windows etc
- [~,Session] = xlsread(path,'Windows','c20:c29');
- Rat={'YVU01' 'YVU02' 'YVU03' 'YVU04' 'YVU05' 'YVU06'};
- sesSel=[1 10];
- else
- load('RAW_FS5.mat')
- path='E:\Youna\Post-doc\MATLAB\Youna Matlab\DT Nex Files\RESULTfs5.xls'; %excel file with windows etc
- [~,Session] = xlsread(path,'Windows','c23:c29');
- Rat={'YVAF2', 'YVV08' 'YVV10' 'YVV11' 'YVV13' 'YVV14' };
- sesSel=[1 7];
- end
-
-
- clear RatName
- SessionName = {RAW.SessionName};
- for i=1:length(RAW) %loops through sessions
- RatName{i,1}=RAW(i).Einfo{1,1}(1:5);
- end
-
- for i=1:length(Session) %loops through sessions
- for y=1:length(Rat)% loop through rats
- ses=strcmp(Session(i),SessionName);
- rat=strcmp(Rat(y),RatName)';
- SesIndex=find(ses & rat);
-
- First_LP=[];
- Middle_LP=[];
- Last_LP=[];
- EvInd_LP=strcmp('LeverPress',RAW(SesIndex).Einfo(:,2));
- EvInd_LLP=strcmp('Last_LP',RAW(SesIndex).Einfo(:,2));
-
- if task<3
- EvInd_FLP=strcmp('First_LP',RAW(SesIndex).Einfo(:,2));
- EvInd_MLP=strcmp('Third_LP',RAW(SesIndex).Einfo(:,2));
- else
- EvInd_FLP=strcmp('First_LPcomp',RAW(SesIndex).Einfo(:,2));
- EvInd_MLP=strcmp('Intermediate_LP',RAW(SesIndex).Einfo(:,2));
- end
-
- First_LP=RAW(SesIndex).Erast{EvInd_FLP};
- Middle_LP=RAW(SesIndex).Erast{EvInd_MLP};
- Last_LP=RAW(SesIndex).Erast{EvInd_LLP};
- LeverPress=RAW(SesIndex).Erast{EvInd_LP};
-
- rat=strcmp(RAW(SesIndex).Einfo{1,1}(1:5),RatName);
- ratIndex=find(rat==1);
-
- FirstP_autocorr=MakePSRlever(LeverPress,First_LP,[0.001 6]);
- MiddleP_autocorr=MakePSRlever(LeverPress,Middle_LP,[-3 3]);
- LastP_autocorr=MakePSRlever(LeverPress,Last_LP,[-6 -0.001]);
- FirstP_autocorr(isnan(FirstP_autocorr)) = [];
- MiddleP_autocorr(isnan(MiddleP_autocorr)) = [];
- LastP_autocorr(isnan(LastP_autocorr)) = [];
-
- [value,edges]=histcounts(FirstP_autocorr,20);
- FirstP_HistVal{i,task}(y,:)=value;
-
- [value,edges]=histcounts(MiddleP_autocorr,20);
- MiddleP_HistVal{i,task}(y,:)=value;
-
- [value,edges]=histcounts(LastP_autocorr,20);
- LastP_HistVal{i,task}(y,:)=value;
- end
- end
-
- FirstP_XVal=linspace(0,5.7,20);
- MiddleP_XVal=linspace(-3,2.7,20);
- LastP_XVal=linspace(-5.7,0,20);
-
- Xaxis=[0 6;-3 3; -6 0];
- Yaxis=[0 30];
- xtitles={'time from LP1','time from ILP','time from LLP'};
- figure(2)
- for i=1:2 %loop thru first last session
- for ev=1:3 %loop thru event
- if ev==1
- Hist=FirstP_HistVal;
- Xval=FirstP_XVal;
- elseif ev==2
- Hist=MiddleP_HistVal;
- Xval=MiddleP_XVal;
- else
- Hist=LastP_HistVal;
- Xval=LastP_XVal;
- end
- Table{ev,i}{task}=Hist{sesSel(i),task};
-
- subplot(2,3,ev+3*(i-1))
- MeanRat_DistribF=nanmean(Hist{sesSel(i),task},1);
- steRat_DistribF=nansem(Hist{sesSel(i),task},1);
- ix=(Xval~=0);
- errorbar(Xval(ix),MeanRat_DistribF(ix),steRat_DistribF(ix),'-o','MarkerSize',6,'Color','b','MarkerFaceColor',ColorsTask(task,:),'MarkerEdgeColor','k','CapSize',0,'LineWidth',1);
- hold on
- for rat=1:6
- plot1=plot(Xval(ix),Hist{sesSel(i),task}(rat,ix),'color',ColorsTask(task,:),'LineWidth',1);
- plot1.Color(4) = 0.2;
- end
- xlabel(xtitles{ev});
- ylabel('Frequency');
- axis([Xaxis(ev,:),Yaxis]);
- set(gca, 'box', 'off')
- end
- end
- end
- %% statistics
- %make table
- rep=0;
- cond={'1st ses, ev1','1st ses, ev2','1st ses, ev3','last ses, ev1','last ses, ev2','last ses, ev3'};
- for session=1:2
- for ev=1:3
- rep=rep+1;
- Table_allTask=cat(1,Table{ev,session}{:});
-
- if ev==2
- ix=(MiddleP_XVal~=0);
- Table_Stat=cat(2,TaskID,Table_allTask(:,ix));
- 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'});
- nbbin=[1:19];
- else
- Table_Stat=cat(2,TaskID,Table_allTask);
- 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'});
- nbbin=[1:20];
- end
- tableSTAT.task=categorical(tableSTAT.task);
- stat(rep).condition=cond{rep};
- rm_reg = fitrm(tableSTAT,'win1-win20~task','WithinDesign',nbbin');
- stat(rep).ranovatbl_event = ranova(rm_reg);
- stat(rep).Btw_ranovatbl_event = anova(rm_reg);
- stat(rep).posthoc = multcompare(rm_reg,'task');
-
- filename = 'ResultStat_behav.xlsx';
- writetable(stat(rep).ranovatbl_event,filename,'Sheet',rep,'Range','A1')
- writetable(stat(rep).Btw_ranovatbl_event,filename,'Sheet',rep,'Range','J1')
- writetable(stat(rep).posthoc,filename,'Sheet',rep,'Range','R1')
- end
- end
|