Fig_2.m~ 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. load('data_fig_2.db','-mat');
  2. res={};
  3. bins=(1:300)*.002;
  4. res.allcells.positive=0*bins;
  5. res.allcells.negative=0*bins;
  6. res.allcells.shuff=zeros(1000,numel(bins));
  7. typ='allcells';
  8. delta_r=5.0666667;
  9. delta_l=30.4;
  10. if 1
  11. for i=1:numel(alldata.ts)
  12. data=alldata.pos{i};
  13. ts=alldata.ts{i};
  14. %%
  15. nlaps=min(numel(data.log.end_r),numel(data.log.end_l));
  16. right=(data.log.start_r(1:nlaps)+delta_r)';
  17. left=(data.log.start_l(1:nlaps)+delta_l)';
  18. dwin=.5;
  19. %% speed
  20. selfast=is_inside(ts',data.log.start_r'+1,data.log.start_r'+4) | is_inside(ts',data.log.start_l'+31.5,data.log.start_l'+34.5);
  21. selslow=is_inside(ts',data.log.start_l'+5,data.log.start_l'+25) | is_inside(ts',data.log.start_r'+8,data.log.start_r'+28);
  22. res.(typ).fast(i,:)=hist(autoc2(ts(selfast)),bins)/6;
  23. res.(typ).slow(i,:)=hist(autoc2(ts(selslow)),bins)/40;
  24. %% acceleration
  25. res.(typ).negative=res.(typ).negative + hist(autoc2(ts(is_inside(ts',right,right+dwin))),bins);
  26. res.(typ).positive=res.(typ).positive + hist(autoc2(ts(is_inside(ts',left,left+dwin))),bins);
  27. for j=1:1000
  28. shuff_fast=data.log.start_r'+1+3*rand(1,nlaps);
  29. shuff_slow=data.log.start_l'+5+20*rand(1,nlaps);
  30. shuff=[shuff_fast shuff_slow];
  31. shuff=shuff(randperm(numel(shuff),numel(shuff)/2));
  32. res.(typ).shuff(j,:)=res.(typ).shuff(j,:)+hist(autoc2(ts(is_inside(ts',shuff,shuff+dwin))),bins);
  33. end
  34. end
  35. save('partial_res.db','res','-mat');
  36. end
  37. %%
  38. %%
  39. close all
  40. bins=(1:150)*.004;
  41. %%
  42. sel=bins>0.01 & bins<0.3;
  43. types={'allcells'};
  44. nshuf=1000;
  45. sname='shuff_speed.mat';
  46. if 0%exist(sname,'file')
  47. load(sname,'-mat')
  48. else
  49. sh_f1={};sh_f2={};
  50. for ty=1:numel(types)
  51. typ=types{ty};
  52. sh_f1.(typ)=zeros(1,nshuf);
  53. sh_f2.(typ)=zeros(1,nshuf);
  54. % aux_all=[.5*(res.(typ).fast(:,1:2:end)+res.(typ).fast(:,2:2:end)); .5*(res.(typ).slow(:,1:2:end)+res.(typ).slow(:,2:2:end)); ]
  55. for j=1:nshuf
  56. if mod(j,100)==0
  57. disp(j);
  58. end
  59. sel=rand(1,size(res.(typ).fast,1))>.5;
  60. aux1=mean([reshape(res.(typ).fast(sel,:),[],150); reshape(res.(typ).slow(~sel,:),[],150)]);
  61. aux2=mean([reshape(res.(typ).fast(~sel,:),[],150); reshape(res.(typ).slow(sel,:),[],150)]);
  62. aux1(end)=0;
  63. aux2(end)=0;
  64. aux1=aux1/max(aux1);
  65. aux2=aux2/max(aux2);
  66. c1=do_fit(bins,aux1);
  67. c2=do_fit(bins,aux2);
  68. sh_f1.(typ)(j)=c1.f;
  69. sh_f2.(typ)(j)=c2.f;
  70. end
  71. end
  72. save(sname,'sh_f1','sh_f2','-mat');
  73. end
  74. %% speed
  75. for ty=numel(types)
  76. typ=types{ty};
  77. f=figure;
  78. hold on;
  79. aux=mean(reshape(res.(typ).fast,[],150))/8;
  80. aux(end)=0;
  81. mxaux=max(aux);
  82. aux=aux/max(aux);
  83. ffast=do_plot(bins,aux,[0 1 0],[.5 1 .5]);
  84. auxs=mean(reshape(res.(typ).slow,[],150))/40;
  85. auxs(end)=0;
  86. mxauxs=max(auxs);
  87. auxs=auxs/max(auxs);
  88. fslow=do_plot2(bins,auxs,[1 0 0],[1 .5*[1 1]]);
  89. subplot(2,2,1)
  90. axis([0 .3 0.3 1.2]);
  91. gl=1.5;
  92. %golden(gl);
  93. set(gca,'YTick',0:.5:2,'FontName','Arial');
  94. subplot(2,2,2)
  95. axis([0 .3 .15*[-1 1] ]);
  96. %golden(gl);
  97. set(gca,'YTick',-.6:.1:.6,'FontName','Arial');
  98. subplot(2,2,3)
  99. fbins=7.5:.01:8.5;
  100. h=hist([sh_f1.(typ) sh_f2.(typ)],fbins);
  101. b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
  102. mx=ceil(2*max(h));
  103. hold on;
  104. legend off;
  105. line((fslow)*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
  106. line(ffast*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
  107. axis([7.6 8.0 0 380]);
  108. axis([7.5 9.5 0 380]);
  109. set(gca,'YTick',0:100:300)
  110. subplot(224)
  111. fbins=7.5:.01:8.5;
  112. h=hist([sh_f1.(typ) sh_f2.(typ)],fbins);
  113. b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
  114. mx=ceil(2*max(h));
  115. hold on;
  116. legend off;
  117. line((fslow)*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
  118. line(ffast*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
  119. axis([7.6 8.0 0 300]);
  120. set(gca,'YTick',0:100:300)
  121. end
  122. %% Acceleration
  123. gs=0;
  124. for ty=numel(types)
  125. typ=types{ty};
  126. % f=figure;
  127. % plot(bins,gauss_boxcar(sum(res.(typ).right.pre,1),gs),'Color',[1 .5 .5]);
  128. hold on;
  129. aux=gauss_boxcar(mean(reshape(res.(typ).right,2,150)),gs);
  130. aux=aux/max(aux);
  131. fm=myplot33(bins,aux,[0 0 0],.5*[1 1 1]);
  132. % plot(bins,gauss_boxcar(sum(res.(typ).left.pre,1),gs),'Color',.5*[1 1 1]);
  133. %%
  134. % plot(bins,aux/max(aux),'Color',[1 0 0]);
  135. aux=gauss_boxcar(mean(reshape(res.(typ).control(1,:),2,150)),gs);
  136. aux=aux/max(aux);
  137. fc=myplot3(bins,aux,[0 1 0],[.5 1 .5]);
  138. % plot(bins,aux/max(aux),'Color',[0 1 0]);
  139. aux=gauss_boxcar(mean(reshape(res.(typ).left,2,150)),gs);
  140. aux=aux/max(aux);
  141. fp=myplot3(bins,aux,[1 0 0],[1 .5*[1 1]]);
  142. end
  143. subplot(2,2,1)
  144. axis([0 .3 0.3 1.2]);
  145. gl=1.5;
  146. golden(gl);
  147. set(gca,'YTick',0:.5:2,'FontName','Arial');
  148. subplot(2,2,2)
  149. axis([0 .3 .15*[-1 1] ]);
  150. golden(gl);
  151. set(gca,'YTick',-.6:.1:.6,'FontName','Arial');