forked from freesurfer/freesurfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_time.m
58 lines (49 loc) · 1.55 KB
/
extract_time.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
function time_series = extract_time(S, sind)
% time_series = extract_time(S, subject_index)
% convert time strings into a vector that is the # of minutes since
% the start of the trial
time_ind = 4 ;
time_strings = S(sind).rows(:,time_ind) ;
month = 1 ;
day = 2 ;
year = 3 ;
hour = 4 ;
min = 5 ;
sec = 6 ;
AM_PM = 7 ;
ntps = length(time_strings) ;
min_index = -1 ;
days_to_minutes = 1.0 / (datenum(0,0,0,0,1,0) - datenum(0,0,0,0,0,0)) ;
time_series = zeros(size(time_strings)) ;
for t=1:ntps
elts = sscanf(char(time_strings(t,:)), '%d/%d/%d %d:%d:%d %cM') ;
if (length(elts) < sec)
time_series(t) = NaN ;
else
if (elts(AM_PM) == 'A') % change 12AM times to be 0 hour
if (elts(hour) == 12)
elts(hour) =0 ;
end
end
if (elts(AM_PM) == 'P') % change >12PM times to be plus 12
if (elts(hour) < 12)
elts(hour) = elts(hour) + 12 ;
end
end
days_since_beginning = datenum(elts(year), elts(month), elts(day),elts(hour), elts(min), elts(sec));
if (min_index < 0)
min_index = t ;
minutes_at_start = days_to_minutes * days_since_beginning ;
end
time_series(t) = (days_since_beginning*days_to_minutes - minutes_at_start) ; ;
end
end
%disp(sprintf('min index %d, first time %d (%s)\n', min_index,time_series(min_index), char(time_strings(min_index,:))));
for t=1:min_index
time_series(t) = time_series(min_index) ;
end
for t=2:length(time_series)
if (isnan(time_series(t)))
time_series(t) = time_series(t-1) ;
end
end