0001 function PlotPhasePrecession(data,stats,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 track = 'linear';
0038 nBins = [100 100];
0039 smooth = 4;
0040 parent = [];
0041 laps = 'all';
0042
0043
0044 if nargin < 1,
0045 error('Incorrect number of parameters (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).');
0046 end
0047
0048 if nargin > 1 && ~isstruct(stats),
0049 varargin = {stats varargin{:}};
0050 stats = [];
0051 end
0052
0053
0054 for i = 1:2:length(varargin),
0055 if ~ischar(varargin{i}),
0056 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).']);
0057 end
0058 switch(lower(varargin{i})),
0059 case 'smooth',
0060 smooth = varargin{i+1};
0061 if ~isdscalar(smooth,'>0'),
0062 error('Incorrect value for property ''smooth'' (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).');
0063 end
0064 case 'nbins',
0065 nBins = varargin{i+1};
0066 if ~isivector(nBins,'>0','#2'),
0067 error('Incorrect value for property ''nBins'' (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).');
0068 end
0069 case 'track',
0070 track = lower(varargin{i+1});
0071 if ~isastring(track,'linear','circular'),
0072 error('Incorrect value for property ''track'' (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).');
0073 end
0074 case 'laps',
0075 laps = lower(varargin{i+1});
0076 if ~isastring(laps,'all','single'),
0077 error('Incorrect value for property ''laps'' (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).');
0078 end
0079 case 'parent',
0080 parent = varargin{i+1};
0081 if ~ishandle(parent),
0082 error('Incorrect value for property ''parent'' (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).');
0083 end
0084 otherwise,
0085 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help PlotPhasePrecession">PlotPhasePrecession</a>'' for details).']);
0086 end
0087 end
0088
0089 if isempty(parent), parent = gcf; end
0090 if strcmp(track,'linear'),
0091 curveType = 'll';
0092 else
0093 curveType = 'cl';
0094 end
0095
0096
0097 t = data.position.t;
0098 x = data.position.x;
0099 pp = data.position.phase;
0100 l = data.position.lap;
0101 r = data.rate.r;
0102 pr = data.rate.phase;
0103 nBinsX = nBins(1);
0104 nBinsP = nBins(2);
0105
0106 if strcmp(laps,'all'),
0107
0108
0109 a = subplot(4,1,1,'parent',parent);
0110 nBins = 200;
0111 curve = FiringCurve(data.x,t,'nbins',nBins,'smooth',2,'type',curveType);
0112 if strcmp(track,'linear'),
0113 plot(curve.x,curve.rate,'b');
0114 xlim([0 1]);
0115 else
0116 plot([curve.x curve.x+1],[curve.rate curve.rate],'b');
0117 xlim([0 2]);
0118 end
0119 set(a,'tickdir','out');
0120 ylabel('Firing Rate (Hz)');
0121
0122
0123 a = subplot(4,1,2,'parent',parent);
0124 if strcmp(track,'linear'),
0125 plot([x;x],[pp;pp+2*pi]*180/pi,'k.','markersize',4);
0126 if ~isempty(stats) && ~isempty(stats.slope),
0127 hold on;
0128 dx = max(x)-min(x);
0129 xm = mean([min(x);max(x)]);
0130 ym = wrap(stats.slope*xm+stats.intercept,2)*180/pi;
0131 PlotSlope(xm,ym,stats.slope*180/pi,dx,'r');
0132 PlotSlope(xm,ym+360,stats.slope*180/pi,dx,'r');
0133 end
0134 xlim([0 1]);
0135 else
0136 plot([x;x;x+1;x+1],[pp;pp+2*pi;pp;pp+2*pi]*180/pi,'k.','markersize',4);
0137 if ~isempty(stats) && ~isempty(stats.slope),
0138 hold on;
0139 if diff(stats.boundaries) < 0,
0140
0141
0142
0143 fieldStart = stats.boundaries(1);
0144 fieldStop = max(x)+stats.boundaries(2);
0145 else
0146 fieldStart = min(x);
0147 fieldStop = max(x);
0148 end
0149 dx = fieldStop - fieldStart;
0150 xm = mean([fieldStop fieldStart]);
0151 ym = wrap(stats.slope*xm+stats.intercept,2)*180/pi;
0152 PlotSlope(xm,ym,stats.slope*180/pi,dx,'r');
0153 PlotSlope(xm,ym+360,stats.slope*180/pi,dx,'r');
0154 PlotSlope(xm+1,ym,stats.slope*180/pi,dx,'r');
0155 PlotSlope(xm+1,ym+360,stats.slope*180/pi,dx,'r');
0156 end
0157 xlim([0 2]);
0158 end
0159 set(a,'ytick',0:90:720,'ylim',[0 720],'tickdir','out');
0160 ylabel('Phase (°)');
0161
0162
0163 a = subplot(4,1,3,'parent',parent);
0164 x0 = Bin(x,[0 1],nBinsX);
0165 p0 = Bin(pp,[0 2*pi],nBinsP);
0166 map = Accumulate([p0 x0],1,[nBinsP nBinsX]);
0167 if strcmp(track,'linear'),
0168 map = [map;map];
0169 map = Smooth(map,2);
0170 PlotColorMap(map,1,'x',linspace(0,1,nBinsX+1),'y',0:6:720);
0171 else
0172 map = [map map;map map];
0173 map = Smooth(map,smooth);
0174 PlotColorMap(map,1,'x',linspace(0,2,2*nBinsX+1),'y',0:6:720);
0175 end
0176 set(a,'ytick',0:90:720,'ylim',[0 720],'tickdir','out','ydir','normal');
0177 xlabel('Position');
0178 ylabel('Phase (°)');
0179
0180
0181 a = subplot(4,1,4,'parent',parent);
0182 if isempty(r), return; end
0183 rnd = randn(size(r))/5;
0184 plot(r+rnd,pr*180/pi,'k.','markersize',4);
0185 hold on;
0186 n = max(r);
0187 for i = 1:n,
0188 if any(r==i),
0189 [m(i,1),c(i,:)] = CircularConfidenceIntervals(pr(r==i));
0190 else
0191 m(i,1) = NaN;
0192 c(i,1:2) = NaN;
0193 end
0194 end
0195 neg = m<0;
0196 m(neg) = m(neg)+2*pi;
0197 c(neg,:) = c(neg,:)+2*pi;
0198 m = m*180/pi;
0199 c = c*180/pi;
0200 errorbar(1:n,m,m-c(:,2),c(:,1)-m,'r');
0201 set(a,'ytick',0:90:360,'ylim',[0 360],'tickdir','out');
0202 xlabel('Firing Rate (spikes / 2 cycles)');
0203 ylabel('Phase (°)');
0204
0205 else
0206
0207 colors = 'bk';
0208
0209
0210 laps = unique(data.position.lap);
0211 laps = laps(laps~=0);
0212 nLaps = length(laps);
0213
0214
0215 a = subplot(2,1,1,'parent',parent);
0216 hold on;
0217 nBins = 200;
0218 curve = FiringCurve(data.x,t,'nbins',nBins,'smooth',2,'type',curveType);
0219 for i = 1:nLaps,
0220 style = colors(mod(i,2)+1);
0221 if strcmp(track,'linear'),
0222 plot(curve.x+(i-1),curve.rate,style,'markersize',4);
0223 xlim([0 nLaps]);
0224 else
0225 plot([curve.x curve.x+1]+2*(i-1),[curve.rate curve.rate],style,'markersize',4);
0226 xlim([0 2*nLaps]);
0227 end
0228 end
0229 set(a,'tickdir','out','xtick',1:nLaps,'xticklabel',[]);
0230 xlabel('Position');
0231 ylabel('Firing Rate (Hz)');
0232
0233
0234 a = subplot(2,1,2,'parent',parent);
0235 hold on;
0236 for i = 1:nLaps,
0237 style = [colors(mod(i,2)+1) '.'];
0238 if strcmp(track,'linear'),
0239 plot([x(l==i);x(l==i)]+(i-1),[pp(l==i);pp(l==i)+2*pi]*180/pi,style,'markersize',4);
0240 if ~isempty(stats) && ~isempty(stats.slope),
0241 hold on;
0242 dx = max(x(l==i))-min(x(l==i));
0243 xm = mean([min(x(l==i));max(x(l==i))])+(i-1);
0244 ym = wrap(stats.lap.slope(i)*xm+stats.lap.intercept(i),2)*180/pi;
0245 PlotSlope(xm,ym,stats.lap.slope(i)*180/pi,dx,'r');
0246 PlotSlope(xm,ym+360,stats.lap.slope(i)*180/pi,dx,'r');
0247 end
0248 xlim([0 nLaps]);
0249 else
0250 plot([x(l==i);x(l==i);x(l==i)+1;x(l==i)+1]+2*(i-1),[pp(l==i);pp(l==i)+2*pi;pp(l==i);pp(l==i)+2*pi]*180/pi,style,'markersize',4);
0251 if ~isempty(stats) && ~isempty(stats.slope),
0252 hold on;
0253 dx = max(x(l==i))-min(x(l==i));
0254 xm = mean([min(x(l==i));max(x(l==i))]);
0255 ym = wrap(stats.lap.slope(i)*xm+stats.lap.intercept(i),2)*180/pi;
0256 PlotSlope(xm+2*(i-1),ym,stats.lap.slope(i)*180/pi,dx,'r');
0257 PlotSlope(xm+2*(i-1),ym+360,stats.lap.slope(i)*180/pi,dx,'r');
0258 PlotSlope(xm+1+2*(i-1),ym,stats.lap.slope(i)*180/pi,dx,'r');
0259 PlotSlope(xm+1+2*(i-1),ym+360,stats.lap.slope(i)*180/pi,dx,'r');
0260 end
0261 xlim([0 2*nLaps]);
0262 end
0263 end
0264 set(a,'ytick',0:90:720,'ylim',[0 720],'tickdir','out','xtick',1:nLaps,'xticklabel',[]);
0265 xlabel('Position');
0266 ylabel('Phase (°)');
0267
0268 end