-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpstructLH.m
102 lines (88 loc) · 2.45 KB
/
pstructLH.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
%% PstructLH
%{
Structure describing a potentially calibrated parameter
valueV
default values; used when not calibrated
doCal
can take on any value; can determine under what condition a parameter is calibrated
%}
classdef pstructLH < handle
properties
name % name, such as prefBeta
symbolStr % symbol used in paper
descrStr % Long description used in param tables
valueV % default values if not calibrated
% bounds if calibrated
% scalars are expanded to size of valueV
lbV
ubV
doCal % is it calibrated?
end
methods
%% Constructor
function p = pstructLH(nameStr, symbolStr, descrStr, valueV, lbV, ubV, doCal)
p.name = nameStr;
p.symbolStr = symbolStr;
p.descrStr = descrStr;
p.valueV = valueV;
%p.lbV = lbV;
%p.ubV = ubV;
p.doCal = doCal;
p.set_bounds(lbV, ubV);
validate(p);
end
%% Update with new data
function update(p, valueV, lbV, ubV, doCal)
if ~isempty(valueV)
p.valueV = valueV;
end
if ~isempty(doCal)
p.doCal = doCal;
end
p.set_bounds(lbV, ubV);
validate(p);
end
%% Set bounds with scalar expansion
function set_bounds(p, lbV, ubV)
if ~isempty(lbV)
if length(lbV) == 1 && length(p.valueV) > 1
p.lbV = repmat(lbV, size(p.valueV));
else
p.lbV = lbV;
end
end
if ~isempty(ubV)
if length(ubV) == 1 && length(p.valueV) > 1
p.ubV = repmat(ubV, size(p.valueV));
else
p.ubV = ubV;
end
end
end
%% Validate values in struct
function validate(p)
% if ~any(p.doCal == [p.calBase, p.calNever, p.calExp])
% error('Invalid doCal');
% end
validateattributes(p.doCal, {'double'}, {'finite', 'nonnan', 'nonempty', 'integer', 'scalar'})
validateattributes(p.lbV, {'double'}, {'finite', 'nonnan', 'nonempty', 'real', 'size', size(p.valueV)})
if any(p.lbV >= p.ubV)
error('Invalid bounds');
end
end
end
end
% %% Validate doCal input
% function validate_docal(doCal)
% if doCal ~= 0 && doCal ~= 1
% error('Invalid doCal');
% end
% end
%
% %% Validate bounds
% function validate_bounds(lbV, ubV)
% validateattributes(lbV, {'double'}, {'finite', 'nonnan', 'nonempty', 'real', 'size', size(ubV)})
% if any(lbV >= ubV)
% error('Invalid bounds');
% end
% end