-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB03_cleanData.m
More file actions
44 lines (33 loc) · 1.27 KB
/
B03_cleanData.m
File metadata and controls
44 lines (33 loc) · 1.27 KB
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
% Load the data
%load('processedAnimalData.mat');
%%%
%WARNING: only run step 1 if just post trials are being analyzed
%%%
% Step 1: Remove entries where nansum(x.data.X_mm) == 0
indicesToDelete = arrayfun(@(x) nansum(x.data.X_mm) == 0, animal);
animal(indicesToDelete) = [];
% Step 2: Ensure each day/group/ROI combination has both 'pre' and 'post' phases
% Convert animal to a table for easier manipulation
animalTable = struct2table(animal);
% Get unique combinations of day, group, and roi
[unique_combinations, ~, ic] = unique(animalTable(:, {'day', 'group', 'roi'}), 'rows');
indicesToKeep = false(height(animalTable), 1);
for i = 1:height(unique_combinations)
% Get the indices for the current combination
combo_indices = find(ic == i);
% Check for 'pre' and 'post' phases
phases = animalTable.phase(combo_indices);
if any(strcmp(phases, 'pre')) && any(strcmp(phases, 'post'))
indicesToKeep(combo_indices) = true;
end
end
% Keep only the valid entries
animal = table2struct(animalTable(indicesToKeep, :))';
clearvars -except animal
% Save the cleaned data
save('cleanedAnimalData.mat', 'animal');
% % quickly look at perf of all rois - for priors
%
% for ij=1:numel(animal)
% prior(ij)=nanmedian(animal(ij).data.performance_index_binned)
% end