-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTrigId.m
More file actions
34 lines (26 loc) · 923 Bytes
/
getTrigId.m
File metadata and controls
34 lines (26 loc) · 923 Bytes
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
function [trigId] = getTrigId(imgId,isTarget)
% Check inputs
if ~isnumeric(imgId) || ~(isnumeric(isTarget) || islogical(isTarget))
error('Bad inputs');
end
if any(size(imgId)~=size(isTarget)) && (numel(isTarget)>1)
error('Dimensions of input are not compatible;');
end
% Expand isTarget if needed
if numel(imgId) > numel(isTarget)
isTarget = isTarget.*ones(size(imgId));
end
% Cast inputs as cell arrays
imgId = num2cell(imgId);
isTarget = num2cell(isTarget);
% isTarget: {0/false,1/true} -> {"0","1"}
isTarget = cellfun(@(ii){num2str(ii)},isTarget);
% catId ∈ {0,1...8} [expressed in binary]
catId = cellfun(@(ii){dec2bin(floor(ii/6),4)},imgId);
% imgNum ∈ {0,1...5} [expressed in binary]
imgNum = cellfun(@(ii){dec2bin(mod(ii,6),3)},imgId);
% Put it all together
trigId = cellfun(@(s1,s2,s3){[s1,s2,s3]},isTarget,catId,imgNum);
% Convert binary to double
trigId = cellfun(@bin2dec,trigId);
return