-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplingrate.m
More file actions
136 lines (126 loc) · 4.19 KB
/
Copy pathsamplingrate.m
File metadata and controls
136 lines (126 loc) · 4.19 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
classdef samplingrate
%SAMPLINGRATE Data collection sampling rate in several units.
% All input is rounded to the nearest second before being converted
% to other units.
%
% Constructor syntax:
% obj = samplingrate(epoch,units)
% epoch - A single numeric value of the sampling rate
% units - 'days','hours','minutes','seconds','hertz'
%
% SAMPLINGRATE properties:
% days - sampling rate in days
% hours - sampling rate in hours
% minutes - sampling rate in minutes
% seconds - sampling rate in seconds
% hertz - sampling rate in hertz
%
% All properties are dependent. Changing one property will update all
% the others.
%
% EXAMPLES:
% epoch = samplingrate(30,'seconds');
% rateInHertz = epoch.hertz;
%
% See also DAYSIMETER12.CONVERTCDF.
% Copyright 2014-2014 Rensselaer Polytechnic Institute
properties(Dependent)
days
hours
minutes
seconds
hertz
end
properties(Access=private)
privateDays
privateHours
privateMinutes
privateSeconds
privateHertz
end
methods
% Object creation
function obj = samplingrate(epoch,units)
units = lower(units);
switch units
case 'days'
obj.days = epoch;
case 'hours'
obj.hours = epoch;
case 'minutes'
obj.minutes = epoch;
case 'seconds'
obj.seconds = epoch;
case 'hertz'
obj.hertz = epoch;
otherwise
error('Unknown units');
end % End of switch
end % End of function
% Get and set days.
function epoch = get.days(obj)
epoch = obj.privateDays;
end
function obj = set.days(obj,epoch)
obj.privateDays = epoch;
% Round to whole seconds.
seconds = round(epoch*24*60*60);
obj.privateHours = seconds/(60*60);
obj.privateMinutes = seconds/60;
obj.privateSeconds = seconds;
obj.privateHertz = 1/seconds;
end
% Get and set hours.
function epoch = get.hours(obj)
epoch = obj.privateHours;
end
function obj = set.hours(obj,epoch)
obj.privateHours = epoch;
% Round to whole seconds.
seconds = round(epoch*60*60);
obj.privateDays = seconds/(24*60*60);
obj.privateMinutes = seconds/60;
obj.privateSeconds = seconds;
obj.privateHertz = 1/seconds;
end
% Get and set minutes.
function epoch = get.minutes(obj)
epoch = obj.privateMinutes;
end
function obj = set.minutes(obj,epoch)
obj.privateMinutes = epoch;
% Round to whole seconds.
seconds = round(epoch*60);
obj.privateDays = seconds/(24*60*60);
obj.privateHours = seconds/(60*60);
obj.privateSeconds = seconds;
obj.privateHertz = 1/seconds;
end
% Get and set seconds.
function epoch = get.seconds(obj)
epoch = obj.privateSeconds;
end
function obj = set.seconds(obj,epoch)
% Round to whole seconds.
seconds = round(epoch);
obj.privateSeconds = seconds;
obj.privateDays = seconds/(24*60*60);
obj.privateHours = seconds/(60*60);
obj.privateMinutes = seconds/60;
obj.privateHertz = 1/seconds;
end
% Get and set hertz.
function epoch = get.hertz(obj)
epoch = obj.privateHertz;
end
function obj = set.hertz(obj,epoch)
obj.privateHertz = epoch;
% Round to whole seconds.
seconds = round(1/epoch);
obj.privateDays = seconds/(24*60*60);
obj.privateHours = seconds/(60*60);
obj.privateMinutes = seconds/60;
obj.privateSeconds = seconds;
end
end
end