123456789101112131415161718192021222324252627282930313233 |
- function [R_base,Spiketimes_single_rat] = Data_prepare(Spike_times,animal_id,Trial_times,binsize)
- % This function rearranges and perepares the data for the decomposition
- % Inputs :
- % Spike_times : a cell array consisiting the spike times of the each unit
- % animal_id : a cell array consisiting the id of the animal for each unit
- % Trial Times : A vector containing the end time of the trials
- % binsize : the time (in msc) used for the binning
- % Outputs :
- % R_whole : The cell of the binned data (size : N*T*S N = Number of units
- % T = length of the experiment, S = Number of Trials/Animals )
- % R_base : Same as R_whole but before the stimulus
- animal_id_number = zeros(length(animal_id),1);
- for i=1:length(animal_id)
- animal_id_number(i) = str2num(animal_id{i});
- end
- %animal_id_number_sorted = sort(animal_id_number);
- animal_id_number_sorted = animal_id_number;
- %animal_id_unique = unique(animal_id_number_sorted);
- animal_id_unique = unique(animal_id_number,'stable');
- R_whole = cell(1,length(animal_id_unique));
- R_base = R_whole;
- parfor i=1:length(animal_id_unique)
- idx_first = find(animal_id_number_sorted == animal_id_unique(i),1,'first');
- idx_last = find(animal_id_number_sorted == animal_id_unique(i),1,'last');
- Spikes_single_rat = Spike_times(idx_first:idx_last);
- Spiketimes_single_rat{i} = Spike_times(idx_first:idx_last);
- Spikes_single_rat = cellfun(@(x) x*1000,Spikes_single_rat,'un',0);
- endtime_base = Trial_times(idx_last)*1000;
- %endtime = max(cell2mat(Spikes_single_rat)) + 10*1000;
- R_base{i} = count_spikes(Spikes_single_rat',binsize,endtime_base);
- %R_whole{i} = count_spikes(Spikes_single_rat',binsize,endtime);
- end
- end
|