ChooseNs.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. function [All,First,Last,Custom]=ChooseNs(R,DOI,ROI)
  2. %a code to get "early" neurons and "late" neurons and "all" where no channel is
  3. %repeated across multiple days for any rat
  4. alls=DOI; %which days to look at
  5. Rat={};
  6. Day=[];
  7. Channel=[];
  8. %breaking it down by session
  9. for i=1:length(R.Ninfo)
  10. A=char(R.Ninfo(i,1));
  11. Rat(i,1)=cellstr(A(1:3));
  12. RatNum(i,1)=str2num(A(2:3));
  13. Day(i,1)=str2num(A(8:9));
  14. B=char(R.Ninfo(i,2));
  15. Channel(i,1)=str2num(B(4:5));
  16. end
  17. earlies=min(Day);
  18. C=unique(Rat(:,1));
  19. D=unique(Day(:,1));
  20. E=unique(Channel(:,1));
  21. %count number of neurons on each channel
  22. for i=1:length(C)
  23. Subj=strcmp(C(i),Rat);
  24. for j=D(1):D(end)
  25. % if R.CueRatio(i,j)>0.6 && R.CueRatio(i,j)<0.8
  26. for k=1:length(E)
  27. neurons{i,1}(k,j)=sum(Subj&Day==j&Channel==k);
  28. end
  29. % else
  30. % for k=1:length(E)
  31. % neurons{i,1}(k,j)=0;
  32. % end
  33. % end
  34. end
  35. end
  36. %pick the session with most neurons for each channel
  37. for i=1:length(C)
  38. lates(i,1)=max(Day(strcmp(C(i),Rat)));
  39. for k=1:length(E)
  40. [~,earlysess{i,1}(k,1)]=max(neurons{i,1}(k,earlies));
  41. [~,latesess{i,1}(k,1)]=max(neurons{i,1}(k,lates(i,1)));
  42. [~,allsess{i,1}(k,1)]=max(neurons{i,1}(k,alls));
  43. end
  44. end
  45. %reset the logical
  46. Ear=strcmp('nothing',R.Ninfo(:,1)); %this just makes all zeros
  47. Lat=strcmp('nothing',R.Ninfo(:,1));
  48. All=strcmp('nothing',R.Ninfo(:,1));
  49. %create the selection
  50. for i=1:length(C)
  51. Subj=strcmp(C(i),Rat);
  52. for k=1:length(E)
  53. Ear=Ear|(Subj&Channel==k&Day==(earlies(1)-1+earlysess{i,1}(k,1)));
  54. Lat=Lat|(Subj&Channel==k&Day==(lates(i,1)-1+latesess{i,1}(k,1)));
  55. All=All|(Subj&Channel==k&Day==(alls(1)-1+allsess{i,1}(k,1)));
  56. end
  57. end
  58. %which rats
  59. rats=RatNum<0;
  60. for i=1:length(ROI)
  61. rats=rats | RatNum==ROI(i);
  62. end
  63. All=All & rats;
  64. First=Ear & rats;
  65. Last=Lat & rats;