0001 function [curves,stats] = SurveyTuningCurves(units,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
0038
0039 minv = [];
0040 pixel = [];
0041 show = 'on';
0042 type = 'cartesian';
0043
0044
0045 if ~(nargin >= 1 && isimatrix(units)),
0046 units = GetUnits;
0047 varargin = {units,varargin{:}};
0048 else
0049 all = units(:,2) == -1;
0050 groups = unique(units(all,1));
0051 units(all,:) = [];
0052 units = unique([units;GetUnits(groups)],'rows');
0053 end
0054 nUnits = size(units,1);
0055
0056 if mod(length(varargin),2) ~= 0,
0057 error('Incorrect number of parameters (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).');
0058 end
0059
0060
0061 for i = 1:2:length(varargin),
0062 if ~ischar(varargin{i}),
0063 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).']);
0064 end
0065 switch(lower(varargin{i})),
0066 case 'minv',
0067 minv = varargin{i+1};
0068 if ~isdscalar(minv,'>=0'),
0069 error('Incorrect value for property ''minv'' (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).');
0070 end
0071 case 'pixel',
0072 pixel = varargin{i+1};
0073 if ~isdscalar(pixel,'>0'),
0074 error('Incorrect value for property ''pixel'' (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).');
0075 end
0076 case 'show',
0077 show = varargin{i+1};
0078 if ~isastring(show,'on','off'),
0079 error('Incorrect value for property ''show'' (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).');
0080 end
0081 case 'type',
0082 type = varargin{i+1};
0083 if ~isastring(type,'polar','cartesian'),
0084 error('Incorrect value for property ''type'' (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).');
0085 end
0086 otherwise,
0087 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).']);
0088 end
0089 end
0090
0091
0092 positions = GetPositions;
0093 if isempty(positions), warning('No positions found for current subsession'); return; end
0094 if ~isempty(minv),
0095 if isempty(pixel),
0096 error('Missing pixel size for minimum velocity (type ''help <a href="matlab:help SurveyFiringMaps">SurveyFiringMaps</a>'' for details).');
0097 end
0098 x = GetPositions('coordinates','real','pixel',pixel);
0099 v = LinearVelocity(x,30);
0100 [~,in] = Threshold(v,'>',minv,'min',10,'max',2);
0101 positions = positions(in,:);
0102
0103 end
0104
0105
0106 angles = GetAngles;
0107 angles(:,2) = (angles(:,2)+pi)/(2*pi);
0108
0109
0110 start = GetEvents('beginning of .*');
0111 stop = GetEvents('end of .*');
0112 nSubsessions = length(start);
0113
0114 if strcmp(show,'on'),
0115 titles = GetEventTypes('beginning of .*');
0116 status = Hide('status');
0117 Hide('on');
0118 figureList = [];
0119 end
0120
0121 try
0122 n = 0;
0123
0124 for j = 1:nUnits,
0125 if strcmp(show,'on'), figureList = [figureList figure]; end
0126 spikes = GetSpikes(units(j,:));
0127
0128 for i = 1:nSubsessions,
0129 a = Restrict(angles,[start(i) stop(i)]);
0130 s = Restrict(spikes,[start(i) stop(i)]);
0131 if nargout == 0,
0132 curve = FiringCurve(a,s,'nbins',120,'mintime',0,'type','cl');
0133 else
0134 [curve,st] = FiringCurve(a,s,'nbins',120,'mintime',0,'type','cl');
0135 st.unit = units(j,:);
0136 st.subsession = i;
0137 n = n + 1;
0138 stats(n) = st;
0139 curves(n) = curve;
0140 end
0141 if strcmp(show,'on'),
0142 SquareSubplot(nSubsessions,i);
0143 if strcmp(type,'cartesian'),
0144 plot(curve.x,curve.rate);
0145 else
0146 polar(curve.x*2*pi,curve.rate);
0147 end
0148 title = titles{i}(14:end);
0149 SplitTitle([title ' (' int2str(units(j,1)) '-' int2str(units(j,2)) ')'],round(150/sqrt(nSubsessions)));
0150 end
0151 end
0152 end
0153 catch err
0154 if strcmp(show,'on'),
0155 Hide(status);
0156 Hide(figureList,status);
0157 end
0158 err.rethrow;
0159 end
0160
0161 if strcmp(show,'on'),
0162 Hide(status);
0163 Hide(figureList,status);
0164 end