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