-
Notifications
You must be signed in to change notification settings - Fork 2
/
ComputeNormBehaviorData_Logic.m
59 lines (56 loc) · 1.66 KB
/
ComputeNormBehaviorData_Logic.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
function [normbehaviordata,behaviorfns,stattypes] = ComputeNormBehaviorData_Logic(cmd,normbehaviordata_plus,normbehaviordata_minus,behaviorlabels,varargin)
words = regexp(cmd,'((\{\w+\})|(AND)|(OR)|(NOT))','tokens');
words = [words{:}];
N = size(normbehaviordata_plus,1);
normbehaviordata = nan(N,1);
jointype = '';
isnot = false;
behaviorfns = {};
stattypes = {};
for i = 1:numel(words),
word = words{i};
switch word,
case {'AND','OR'}
jointype = word;
isnot = false;
case 'NOT'
isnot = true;
otherwise
m = regexp(word,'^\{(\w+)_((plus)|(minus))\}$','tokens','once');
fn = m{1};
behaviortype = m{2};
fni = find(strcmp(behaviorlabels,fn));
if numel(fni) ~= 1,
error('Error matching %s to behaviorlabels',fn);
end
if ~ismember(behaviortype,{'plus','minus'}),
error('Unknown behavior type %s',behaviortype);
end
behaviorfns{end+1} = fn; %#ok<AGROW>
stattypes{end+1} = behaviortype; %#ok<AGROW>
if strcmp(behaviortype,'plus'),
x = normbehaviordata_plus(:,fni);
else
x = normbehaviordata_minus(:,fni);
end
switch jointype,
case '',
if isnot,
error('First argument cannot be NOT');
end
normbehaviordata_new = x;
case 'AND'
if isnot,
normbehaviordata_new = max(0,normbehaviordata - x);
else
normbehaviordata_new = min(normbehaviordata,x);
end
case 'OR',
if isnot,
x = 1-x;
end
normbehaviordata_new = min(1,normbehaviordata+x);
end
normbehaviordata = normbehaviordata_new;
end
end