Data_prepare.m 1.7 KB

123456789101112131415161718192021222324252627282930313233
  1. function [R_base,Spiketimes_single_rat] = Data_prepare(Spike_times,animal_id,Trial_times,binsize)
  2. % This function rearranges and perepares the data for the decomposition
  3. % Inputs :
  4. % Spike_times : a cell array consisiting the spike times of the each unit
  5. % animal_id : a cell array consisiting the id of the animal for each unit
  6. % Trial Times : A vector containing the end time of the trials
  7. % binsize : the time (in msc) used for the binning
  8. % Outputs :
  9. % R_whole : The cell of the binned data (size : N*T*S N = Number of units
  10. % T = length of the experiment, S = Number of Trials/Animals )
  11. % R_base : Same as R_whole but before the stimulus
  12. animal_id_number = zeros(length(animal_id),1);
  13. for i=1:length(animal_id)
  14. animal_id_number(i) = str2num(animal_id{i});
  15. end
  16. %animal_id_number_sorted = sort(animal_id_number);
  17. animal_id_number_sorted = animal_id_number;
  18. %animal_id_unique = unique(animal_id_number_sorted);
  19. animal_id_unique = unique(animal_id_number,'stable');
  20. R_whole = cell(1,length(animal_id_unique));
  21. R_base = R_whole;
  22. parfor i=1:length(animal_id_unique)
  23. idx_first = find(animal_id_number_sorted == animal_id_unique(i),1,'first');
  24. idx_last = find(animal_id_number_sorted == animal_id_unique(i),1,'last');
  25. Spikes_single_rat = Spike_times(idx_first:idx_last);
  26. Spiketimes_single_rat{i} = Spike_times(idx_first:idx_last);
  27. Spikes_single_rat = cellfun(@(x) x*1000,Spikes_single_rat,'un',0);
  28. endtime_base = Trial_times(idx_last)*1000;
  29. %endtime = max(cell2mat(Spikes_single_rat)) + 10*1000;
  30. R_base{i} = count_spikes(Spikes_single_rat',binsize,endtime_base);
  31. %R_whole{i} = count_spikes(Spikes_single_rat',binsize,endtime);
  32. end
  33. end