-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcarrayGetElements.m
79 lines (62 loc) · 2.01 KB
/
mcarrayGetElements.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
function entries = mcarrayGetElements(d,queryType,query,varargin)
%
% Selects those entries of an array that satisfy a condition
%
%
% entries = mcarrayGetElements(data,queryType,query,'name','value')
%
%
% Examples:
% mcarrayGetElements(data,'namecontains','Subject1')
% mcarrayGetElements(data,'namecontains','Subject1','outputtype','entries')
% mcarrayGetElements(data,'namecontains','subJECT1','ignoreCase',0)
% mcarrayGetElements(data,'nFrames',1000)
% mcarrayGetElements(data,'type','norm data')
% mcarrayGetElements(data,'type','segm data','outputtype','entries')
%
% By Kristian Nymoen, RITMO/University of Oslo, 2019
%
%
outputType = 'data';
ignoreCase = 1;
for k=1:2:length(varargin)
if strcmpi(varargin{k}, 'outputType')
outputType=varargin{k+1};
elseif strcmpi(varargin{k}, 'ignoreCase')
ignoreCase=varargin{k+1};
else
str=sprintf('Input argument %s unknown.', varargin{k});
disp([10, str, 10])
end
end
switch lower(queryType)
case 'namecontains'
[~,files,~]=cellfun(@fileparts,{d.filename},'Uni',0);
if strcmpi(outputType,'indecies')
entries = find(contains(files,query,'IgnoreCase',ignoreCase));
else
entries = d(contains(files,query,'IgnoreCase',ignoreCase));
end
otherwise
if isfield(d,queryType)
if isnumeric(query)
if strcmpi(outputType,'indecies')
entries = find([d.(queryType)] == query);
else
entries = d([d.(queryType)] == query);
end
else
if strcmpi(outputType,'indecies')
entries = find(strcmpi({d.(queryType)}, query));
else
entries = d(strcmpi({d.(queryType)}, query));
end
end
else
error('The second argument must be either ''namecontains'' or a field in the input struct')
end
end
if isempty(entries)
entries = [];
end
end