-
Notifications
You must be signed in to change notification settings - Fork 0
/
measurement.m
92 lines (82 loc) · 2.09 KB
/
measurement.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
classdef measurement
%MEASUREMENT Describe an experimental measurement.
% The measurement class contains descriptive information about data
% obtained experimentally.
properties % For example:
name = ''; % 'Ambient Temperature'
symbol = ''; % 'T_o'
units = ''; % 'K'
value = []; % 293.15
end
properties (Dependent)
print % 'Ambient Temperature, T_o: 293.15 K'
describe % 'Ambient Temperature, T_o [K]'
end
methods
%
% Constructor
%
function m = measurement( name, symbol, units, value )
if nargin>0, m.name = name; end
if nargin>1, m.symbol = symbol; end
if nargin>2, m.units = units; end
if nargin>3, m.value = value; end
end
%
% Object set methods
%
function obj = set.name( obj, val )
if ischar(val), obj.name = val;
else error('NAME property must be a string.');
end
end
function obj = set.symbol( obj, val )
if ischar(val), obj.symbol = val;
else error('SYMBOL property must be a string.');
end
end
function obj = set.units( obj, val )
if ischar(val), obj.units = val;
else error('UNITS property must be a string.');
end
end
function obj = set.value( obj, val )
% For flexibility, no restrictions are placed on the data type
% of the measurement value
obj.value = val;
end
%
% Object get methods
%
function val = get.print( obj )
% Print everything known about the measurement (useful for
% debugging)
% FORMAT: (name)(, symbol)(: value (units))
val = obj.name;
if ~isempty( obj.symbol )
val = [val ', ' obj.symbol];
end
if ~isempty( obj.value )
if numel(obj.value) == 1
val = [val ': ' num2str(obj.value)];
else
val = [val ': <matrix>'];
end
if ~isempty( obj.units )
val = [val ' ' obj.units];
end
end
end
function val = get.describe( obj )
% Describe the measurement (useful for labeling axes)
% FORMAT: (name)(, symbol)( [units])
val = obj.name;
if ~isempty( obj.symbol )
val = [val ', ' obj.symbol];
end
if ~isempty( obj.units )
val = [val ' [' obj.units ']'];
end
end
end
end