-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcatenate_trains.m
87 lines (77 loc) · 3.05 KB
/
concatenate_trains.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
% This file sorts the spike trains by TNR intensity and then concatenates
% them accordingly. The output is a 16x7 cell array with 16 rows of neurons
% and 7 columns of TNR intensities. Inside each cell is the concatenated
% spike train corresponding to all trials for a specific neuron with a
% specific TNR intensity.
% Load spike trains
spike_trains = load('spike_trains.mat');
% load('filtered_stimulus.mat');
load('amplitude.mat');
spike_trains = spike_trains.spike_array;
% Remove first column (TNR intensity)
spike_trains(:,:,1) = [];
% All bins with spikes become +1
spike_trains(spike_trains > 0) = 1;
% All bins with spikes become -1
spike_trains(spike_trains == 0) = -1;
% Load TNR indices
TNR_index = load('TNR_index.mat');
TNR_index = TNR_index.ind;
% Number of TNR intensities, from 0 to 85
num_TNRs = 7;
num_neurons = 16;
% Preallocate cell array with 7 columns of TNR intensities
TNRsorted_trains = cell(1,7);
TNRstimuli = cell(1,7);
% For each TNR intensity...
for i = 1:num_TNRs
% Find trials with TNR intensity i
ind = (TNR_index == i);
% Store trials with TNR intensity i in cell column i
TNRsorted_trains{1,i} = spike_trains(:,ind,:);
%TNRstimuli{1,i} = filtered_stimulus(:,ind,:);
TNRstimuli{1,i} = amplitude(ind,:);
end
% Preallocate cell array with 16 rows of neurons and 7 columns of TNR intensities
sorted_trains = cell(16,7);
sorted_stimuli = cell(16,7);
sorted_amplitudes = cell(1, 7);
% For each TNR intensity...
for i = 1:num_TNRs
% Get TNR trials for that intensity
TNRtrials = TNRsorted_trains{1,i};
TNRtrials_stimuli = TNRstimuli{1,i};
s2 = size(TNRtrials_stimuli, 1);
s3 = size(TNRtrials_stimuli, 2);
amplitudetrials = permute(TNRtrials_stimuli, [2 1]);
amplitudetrials = reshape(amplitudetrials, 1, []);
sorted_amplitudes{i} = amplitudetrials
% For each neuron...
for j = 1:num_neurons
% Get specific trials for that neuron
neurontrials = TNRtrials(j,:,:);
s2 = size(neurontrials,2);
s3 = size(neurontrials,3);
neurontrials = permute(neurontrials, [1 3 2]);
% neurontrials = reshape(neurontrials, [s3, s2]);
% Concatenate trains into 1 row vector
neurontrials = reshape(neurontrials, 1, []);
% Save concatenated train in cell array
sorted_trains{j,i} = neurontrials;
% Get specific trials for that neuron
% stimulustrials = TNRtrials_stimuli(j,:,:);
% s2 = size(stimulustrials,2);
% s3 = size(stimulustrials,3);
% stimulustrials = permute(stimulustrials, [1 3 2]);
% % stimulustrials = reshape(stimulustrials, [s3, s2]);
% % Concatenate trains into 1 row vector
% stimulustrials = reshape(stimulustrials, 1, []);
% % Save concatenated train in cell array
% sorted_stimuli{j,i} = stimulustrials;
end
% Print i
i
end
save('sorted_trains.mat', 'sorted_trains');
% save('sorted_stimuli.mat', 'sorted_stimuli');
sorted('sorted_amplitudes.mat', 'sorted_amplitudes');