0001 function [map,timeBins] = SyncMap(synchronized,indices,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 durations = [-0.5 0.5];
0040 nBins = 100;
0041 smooth = [];
0042
0043
0044 if nargin < 2 | mod(length(varargin),2) ~= 0,
0045 error('Incorrect number of parameters (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0046 end
0047
0048
0049 if size(synchronized,2) > 2,
0050 error('Parameter ''synchronized'' is not a Nx2 matrix (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0051 end
0052 if size(indices,2) ~= 1,
0053 error('Parameter ''indices'' is not a vector (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0054 end
0055 if size(indices,1) ~= size(synchronized,1),
0056 error('Parameters ''synchronized'' and ''indices'' have different lengths (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0057 end
0058
0059
0060 for i = 1:2:length(varargin),
0061 if ~ischar(varargin{i}),
0062 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).']);
0063 end
0064 switch(lower(varargin{i})),
0065 case 'durations',
0066 durations = varargin{i+1};
0067 if ~isdvector(durations,'#2','<'),
0068 error('Incorrect value for property ''durations'' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0069 end
0070 case 'nbins',
0071 nBins = varargin{i+1};
0072 if ~isiscalar(nBins,'>0'),
0073 error('Incorrect value for property ''nBins'' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0074 end
0075 case 'smooth',
0076 smooth = varargin{i+1};
0077 if ~isdvector(smooth,'>=0'),
0078 error('Incorrect value for property ''smooth'' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0079 end
0080
0081 otherwise,
0082 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).']);
0083 end
0084 end
0085
0086
0087 if isempty(smooth),
0088 smooth = ceil(0.01*nBins);
0089 end
0090
0091 start = durations(1);
0092 stop = durations(2);
0093 timeBinSize = (stop - start)/nBins;
0094 timeBins = (start:timeBinSize:stop-timeBinSize)+timeBinSize/2;
0095 binnedTime = Bin(synchronized(:,1),durations,nBins);
0096 if size(synchronized,2) == 1,
0097
0098 s = Accumulate([indices binnedTime],1);
0099 map = Smooth(s,smooth);
0100 else
0101
0102 s = Accumulate([indices binnedTime],synchronized(:,2));
0103 n = Accumulate([indices binnedTime],1);
0104 n(n==0) = 1;
0105 map = Smooth(s,[smooth 0])./Smooth(n,[smooth 0]);
0106 end