GetSpikeTimes - Get spike timestamps. USAGE spikes = GetSpikeTimes(units,<options>) units optional list of units, i.e. [electrode group, cluster] pairs; special conventions: 'all' all units [] no units cluster = -1 all clusters except artefacts and MUA cluster = -2 all clusters except artefacts cluster = -3 all clusters (artefacts are assumed to be in cluster 0, and MUA in 1) <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'output' 'time' returns only timestamps, 'full' returns timestamps, electrode groups and clusters, and 'numbered' returns timestamps and arbitrary unique identifiers corresponding to single units (see EXAMPLE below) (default = 'time') ========================================================================= EXAMPLES % timestamps for all spikes s = GetSpikeTimes; % or s = GetSpikeTimes('all'); % timestamps for units [1 7] and [4 3] s = GetSpikeTimes([1 7;4 3]); % timestamps for all single units on electrode group 5, and unit [6 3] s = GetSpikeTimes([5 -1;6 3]); % timestamps for all units on electrode group 5, except artefacts s = GetSpikeTimes([5 -2]); % timestamps, electrode groups and clusters, for all spikes s = GetSpikeTimes('output','full'); % or s = GetSpikeTimes('all','output','full'); % timestamps and identifiers, for units [1 7], [4 3] and [2 5] % unit [1 7] will be assigned number 1, unit [2 5] number 2, and % unit [4 3] number 3, independent from the order in which they are listed s = GetSpikeTimes([1 7;4 3;2 5],'output','numbered'); NOTE An electrode group is an ensemble of closely spaced electrodes that record from the same neurons, e.g. a single wire electrode, or a wire tetrode, or a multisite silicon probe in octrode configuration, etc. SEE See also LoadSpikeTimes, PlotTicks.
0001 function spikes = GetSpikeTimes(units,varargin) 0002 0003 %GetSpikeTimes - Get spike timestamps. 0004 % 0005 % USAGE 0006 % 0007 % spikes = GetSpikeTimes(units,<options>) 0008 % 0009 % units optional list of units, i.e. [electrode group, cluster] pairs; 0010 % special conventions: 0011 % 'all' all units 0012 % [] no units 0013 % cluster = -1 all clusters except artefacts and MUA 0014 % cluster = -2 all clusters except artefacts 0015 % cluster = -3 all clusters 0016 % (artefacts are assumed to be in cluster 0, and MUA in 1) 0017 % <options> optional list of property-value pairs (see table below) 0018 % 0019 % ========================================================================= 0020 % Properties Values 0021 % ------------------------------------------------------------------------- 0022 % 'output' 'time' returns only timestamps, 'full' returns timestamps, 0023 % electrode groups and clusters, and 'numbered' returns 0024 % timestamps and arbitrary unique identifiers corresponding 0025 % to single units (see EXAMPLE below) (default = 'time') 0026 % ========================================================================= 0027 % 0028 % EXAMPLES 0029 % 0030 % % timestamps for all spikes 0031 % s = GetSpikeTimes; 0032 % % or 0033 % s = GetSpikeTimes('all'); 0034 % 0035 % % timestamps for units [1 7] and [4 3] 0036 % s = GetSpikeTimes([1 7;4 3]); 0037 % 0038 % % timestamps for all single units on electrode group 5, and unit [6 3] 0039 % s = GetSpikeTimes([5 -1;6 3]); 0040 % 0041 % % timestamps for all units on electrode group 5, except artefacts 0042 % s = GetSpikeTimes([5 -2]); 0043 % 0044 % % timestamps, electrode groups and clusters, for all spikes 0045 % s = GetSpikeTimes('output','full'); 0046 % % or 0047 % s = GetSpikeTimes('all','output','full'); 0048 % 0049 % % timestamps and identifiers, for units [1 7], [4 3] and [2 5] 0050 % % unit [1 7] will be assigned number 1, unit [2 5] number 2, and 0051 % % unit [4 3] number 3, independent from the order in which they are listed 0052 % s = GetSpikeTimes([1 7;4 3;2 5],'output','numbered'); 0053 % 0054 % NOTE 0055 % 0056 % An electrode group is an ensemble of closely spaced electrodes that record from 0057 % the same neurons, e.g. a single wire electrode, or a wire tetrode, or a multisite 0058 % silicon probe in octrode configuration, etc. 0059 % 0060 % SEE 0061 % 0062 % See also LoadSpikeTimes, PlotTicks. 0063 0064 0065 % Copyright (C) 2004-2017 by Michaƫl Zugaro 0066 % 0067 % This program is free software; you can redistribute it and/or modify 0068 % it under the terms of the GNU General Public License as published by 0069 % the Free Software Foundation; either version 3 of the License, or 0070 % (at your option) any later version. 0071 0072 global DATA; 0073 if isempty(DATA), 0074 error('No session defined (did you forget to call SetCurrentSession? Type ''help <a href="matlab:help Data">Data</a>'' for details).'); 0075 end 0076 0077 % Default values 0078 output = 'time'; 0079 if nargin == 0, units = 'all'; end 0080 0081 % Optional parameter 0082 if ischar(units) && ~strcmp(units,'all'), 0083 varargin = {units,varargin{:}}; 0084 units = 'all'; 0085 else 0086 if ~strcmp(units,'all') && ~isempty(units) && (~isimatrix(units) || size(units,2) ~= 2), 0087 error('Incorrect list of units (type ''help <a href="matlab:help GetSpikeTimes">GetSpikeTimes</a>'' for details).'); 0088 end 0089 end 0090 0091 % Parse parameter list 0092 for i = 1:2:length(varargin), 0093 if ~ischar(varargin{i}), 0094 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help GetSpikeTimes">GetSpikeTimes</a>'' for details).']); 0095 end 0096 switch(lower(varargin{i})), 0097 case 'output', 0098 output = lower(varargin{i+1}); 0099 if ~isastring(output,'time','full','numbered'), 0100 error('Incorrect value for property ''output'' (type ''help <a href="matlab:help GetSpikeTimes">GetSpikeTimes</a>'' for details).'); 0101 end 0102 otherwise, 0103 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help GetSpikeTimes">GetSpikeTimes</a>'' for details).']); 0104 0105 end 0106 end 0107 0108 if isempty(units), 0109 spikes = []; 0110 else 0111 spikes = DATA.spikes; 0112 end 0113 % Adjust output matrix size 0114 if isempty(spikes), 0115 switch(output), 0116 case 'time', 0117 spikes = nan(0,1); 0118 case 'numbered', 0119 spikes = nan(0,2); 0120 case 'full', 0121 spikes = nan(0,3); 0122 end 0123 return 0124 end 0125 0126 % Selected units only 0127 if ~isastring(units,'all'), 0128 nUnits = size(units,1); 0129 selected = zeros(size(spikes(:,1))); 0130 for i = 1:nUnits, 0131 channel = units(i,1); 0132 cluster = units(i,2); 0133 switch cluster, 0134 case -1, 0135 selected = selected | (spikes(:,2) == channel & spikes(:,3) ~= 0 & spikes(:,3) ~= 1); 0136 case -2, 0137 selected = selected | (spikes(:,2) == channel & spikes(:,3) ~= 0); 0138 case -3, 0139 selected = selected | spikes(:,2) == channel; 0140 otherwise, 0141 selected = selected | (spikes(:,2) == channel & spikes(:,3) == cluster); 0142 end 0143 end 0144 spikes = spikes(selected,:); 0145 end 0146 0147 if strcmp(output,'time'), 0148 spikes = spikes(:,1); 0149 elseif strcmp(output,'numbered'), 0150 [units,~,i] = unique(spikes(:,2:end),'rows'); 0151 nUnits = length(units); 0152 index = 1:nUnits; 0153 id = index(i)'; 0154 spikes = [spikes(:,1) id]; 0155 end 0156 0157 spikes = sortrows(spikes,1);