-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_snips_subset.m
49 lines (49 loc) · 2.08 KB
/
get_snips_subset.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
function [snip_subset,Tsub] = get_snips_subset(snips, T, frequency, intensity)
%GET_SNIPS_SUBSET Returns subset of snippets, with indexing table sorted by increasing intensity.
%
% Syntax:
% [snips_subset,Tsub] = get_snips_subset(snips, T);
% [...] = get_snips_subset(snips, T, frequency, intensity);
%
% Inputs:
% snips - If cell, 1 element per freq/intensity/channel/return combo; if tensor, 3rd dim is # stim instances
% T - Table of conditions. If snips is cell, has number of rows equal to number of cell elements. If snips is tensor, has same number of rows as 3rd dimension.
% frequency (1,:) double = []; - Desired frequency subset
% intensity (1,:) double = []; - Desired intensity subset
%
% Output:
% snip_subset - Tensor of snippets that we are interested in
% Tsub - Indexing table for the snippets of interest
%
% See also: Contents
arguments
snips % If cell, 1 element per freq/intensity/channel/return combo; if tensor, 3rd dim is # stim instances
T % Table of conditions. If snips is cell, has number of rows equal to number of cell elements. If snips is tensor, has same number of rows as 3rd dimension.
frequency (1,:) double = []; % Desired frequency subset
intensity (1,:) double = []; % Desired intensity subset
end
if isempty(frequency)
frequency = unique(T.frequency);
end
if isempty(intensity)
intensity = unique(T.intensity);
end
if iscell(snips)
if numel(snips)~=size(T,1)
error("Must have same number of table rows in T as cell elements in snips.");
end
Tsub = sortrows(T(ismember(T.frequency,frequency),:),'intensity','ascend');
Tsub = Tsub(ismember(Tsub.intensity, intensity),:);
index = Tsub.block+1;
snip_subset = cat(3,snips{index});
else
if size(snips,3)~=size(T,1)
error("Must have same number of table rows in T as 3rd dimension size of snips.");
end
iKeep = ismember(T.frequency,frequency) & ismember(T.intensity, intensity);
snip_subset = snips(:,:,iKeep);
Tsub = T(iKeep,:);
[Tsub,index] = sortrows(Tsub,'intensity','ascend');
snip_subset = snip_subset(:,:,index);
end
end