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