-
Notifications
You must be signed in to change notification settings - Fork 0
/
getTimeDoubles.m
146 lines (115 loc) · 4.2 KB
/
getTimeDoubles.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
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
136
137
138
139
140
141
142
143
144
145
146
function [time_doubles1,time_doubles2,time_doubles3, time_doubles4, time_doubles5,...
time_doubles6, saved6, saved3,saved4]= getTimeDoubles(wkv, convertedDates1, convertedDates2,...
convertedDates3, convertedDates4,convertedDates5,...
convertedDates6 )
%GETTIMEDOUBLES
% Using the wkv datetimes (wkv timestamps, first data row) given as input to the function,
% the function outputs the corresponding time doubles (wkv last row of data)
% This function is time consuming from the process of iterating through
% very abundant data. For a sample of roughly 400 seconds of experience run time,
% the function needs 2 min 30 s to complete.
%allow the user to see that the process is occuring through the Matlab
%Command Window if the user so desires.
disp('processing Time doubles');
%% wkv get for timestamp values
[values,~]=wkv_get(wkv, 'timestamp');
%% Initializing variables
indexTime=1 ; k1=1; k2=1; k3=1; k4=1; k5=1; k6=1;
saved1=[]; saved2=[]; saved3=[]; saved4=[]; saved5=[]; saved6=[];
%% Obtaining the indices of the input wkv timestamps
k=[k1,k2,k3,k4,k5,k6];
lengths=[length(convertedDates1), length(convertedDates2), length(convertedDates3), length(convertedDates4), length(convertedDates5), length(convertedDates6)];
while(indexTime<=length(values))
%note that the values are datetimes and not strings from the log so
%necessary to convert them to compare to the string date extracted
%from text
if(k1<=length(convertedDates1))
if(strcmp(datestr( values(indexTime) ), convertedDates1{1,k1}))
saved1=[saved1,indexTime];
k1=k1+1;
end
end
if(k2<=length(convertedDates2))
if(strcmp(datestr( values(indexTime) ), convertedDates2{1,k2}))
saved2=[saved2,indexTime];
k2=k2+1;
end
end
if(k3<=length(convertedDates3))
if(strcmp(datestr( values(indexTime) ), convertedDates3{1,k3}))
saved3=[saved3,indexTime];
k3=k3+1;
end
end
if(k4<=length(convertedDates4))
if(strcmp(datestr( values(indexTime) ), convertedDates4{1,k4}))
saved4=[saved4,indexTime];
k4=k4+1;
end
end
if(k5<=length(convertedDates5))
if(strcmp(datestr( values(indexTime) ), convertedDates5{1,k5}))
saved5=[saved5,indexTime];
k5=k5+1;
end
end
if(k6<=length(convertedDates6))
if(strcmp(datestr( values(indexTime) ), convertedDates6{1,k6}))
saved6=[saved6,indexTime];
k6=k6+1;
end
end
%if all indexes for the 3 vectors of convertedDates have been found
if(k(1)>lengths(1) && k(2)>lengths(2) && k(3)>lengths(3) && k(4)>lengths(4) && k(5)>lengths(5) && k(6)>lengths(6))
break;
end
indexTime=indexTime+1;
end
%% Wkv get for time doubles
[timeDoubles,~]=wkv_get(wkv, 'timestamp_num');
%% Initializing variables
time_doubles1=[]; time_doubles2=[]; time_doubles3=[]; time_doubles4=[]; time_doubles5=[]; time_doubles6=[];
%% From indices, save corresponding time doubles
if(~isempty(convertedDates1))
ind=1;
while(ind<=length(saved1))
time_doubles1=[time_doubles1,timeDoubles(saved1(ind))];
ind=ind+1;
end
end
if(~isempty(convertedDates2))
ind=1;
while(ind<=length(saved2))
time_doubles2=[time_doubles2,timeDoubles(saved2(ind))];
ind=ind+1;
end
end
if(~isempty(convertedDates3))
ind=1;
while(ind<=length(saved3))
time_doubles3=[time_doubles3,timeDoubles(saved3(ind))];
ind=ind+1;
end
end
if(~isempty(convertedDates4))
ind=1;
while(ind<=length(saved4))
time_doubles4=[time_doubles4,timeDoubles(saved4(ind))];
ind=ind+1;
end
end
if(~isempty(convertedDates5))
ind=1;
while(ind<=length(saved5))
time_doubles5=[time_doubles5,timeDoubles(saved5(ind))];
ind=ind+1;
end
end
if(~isempty(convertedDates6))
ind=1;
while(ind<=length(saved6))
time_doubles6=[time_doubles6,timeDoubles(saved6(ind))];
ind=ind+1;
end
end
end