0001 function amplitudes = GetSpikeAmplitudes(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 global DATA;
0035 if isempty(DATA),
0036 error('No session defined (did you forget to call SetCurrentSession? Type ''help <a href="matlab:help Data">Data</a>'' for details).');
0037 end
0038
0039
0040 intervals = [];
0041
0042 if nargin < 1,
0043 error('Incorrect number of parameters (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0044 end
0045
0046 if ~isimatrix(units,'>=-3') || size(units,2) ~= 2,
0047 error('Incorrect unit list (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0048 end
0049
0050
0051 for i = 1:2:length(varargin),
0052 if ~ischar(varargin{i}),
0053 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).']);
0054 end
0055 switch(lower(varargin{i})),
0056 case 'restrict',
0057 intervals = varargin{i+1};
0058 if ~isdmatrix(intervals) || size(intervals,2) ~= 2,
0059 error('Incorrect value for property ''restrict'' (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0060 end
0061 otherwise,
0062 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).']);
0063 end
0064 end
0065
0066 groups = unique(units(:,1));
0067
0068
0069 for i = 1:length(groups),
0070 group = groups(i);
0071 clusters = units(units(:,1)==group,2);
0072 if (ismember(-1,clusters) && ~all(clusters==-1)) || (ismember(-2,clusters) && ~all(clusters==-2)) || (ismember(-3,clusters) && ~all(clusters==-3)),
0073 error('Incompatible list items (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0074 end
0075 end
0076
0077 amplitudes = [];
0078 for i = 1:length(groups),
0079
0080
0081 group = groups(i);
0082 clusters = units(units(:,1)==group,2);
0083
0084
0085 filename = [DATA.session.path '/' DATA.session.basename '.spk.' int2str(group)];
0086 nChannels = length(DATA.spikeGroups.groups{group});
0087 nSamplesPerWaveform = DATA.spikeGroups.nSamples(group);
0088 peak = DATA.spikeGroups.peakSamples(group);
0089 a = LoadSpikeAmplitudes(filename,nChannels,nSamplesPerWaveform,peak,DATA.rates.wideband);
0090
0091
0092 if ismember(-1,clusters),
0093 keep = a(:,3) ~= 0 & a(:,3) ~= 1;
0094 elseif ismember(-2,clusters),
0095 keep = a(:,3) ~= 0;
0096 elseif ismember(-3,clusters),
0097 keep = logical(ones(size(a,1),1));
0098 else
0099 keep = ismember(a(:,3),clusters);
0100 end
0101 a = a(keep,:);
0102
0103
0104 if ~isempty(intervals),
0105 a = Restrict(a,intervals);
0106 end
0107
0108
0109 amplitudes = [amplitudes;a];
0110
0111 end
0112
0113
0114 amplitudes = sortrows(amplitudes);