-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmo_dataset_slice_sa.m
38 lines (33 loc) · 1.13 KB
/
cosmo_dataset_slice_sa.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
function dataset=cosmo_dataset_slice_sa(dataset, samples_to_select)
% Slice a dataset by samples, aka rows
%
% dataset = cosmo_dataset_slice_sa(dataset, samples_to_select)
%
% Input
% dataset: an instance of cosmo_fmri_dataset with N samples
% samples_to_select: Either an Nx1 boolean mask, or a vector with
% indices.
% Returns
% dataset: an instance of an fmri_dataset that is a copy of the input dataset
% but contains just the rows indictated in sample_indices, and the
% corresponding values in sample attributes.
%%
% First slice the samples array by rows
% >>
dataset.samples=dataset.samples(samples_to_select,:);
% <<
%%
% Then go through each of the sample attributes and slice each one.
%
% Hint: we used the matlab function 'fieldnames' to list the field in
% dataset.sa in case it is missing either targets or chunk, or in case there
% may be extra unknown sample attributes
% >>
fns = fieldnames(dataset.sa);
n = numel(fns);
for k=1:n
fn = fns{k};
sa = dataset.sa.(fn);
dataset.sa.(fn)=sa(samples_to_select,:);
end
% <<