Clustering GPS times based on the hour of the day

2 views (last 30 days)
Hello,
I have some raw GPS data that is sampled every 10 minutes or so. I also have the initial timestamp that is the initial recording date and time. I am trying to write a function that returns the index of observations that falls into particular hours of the day, ie. in the hour intervals [ a, b] and [ c, d] (24h clock) and also outside these hours. I try to divide observations contained into these two intervals vs. those outside of these intervals. Thus, all values that fall inside the one of the two intervals are in a vector ' d1' and values outside are in vector ' d2'.
More precisely, my data looks like this:
timeStamp = '16/01/2010__00:01:00' %t0
t %a 1*n vector of time intervals: t = [...,9,10,11,10,10,9,8,10,...]
h %vector of time intervals to split the serie: h = [a,b,c,d]
I would like my function to return the indexes of values that fall to one of the two sets ( d1 or d2). The vector t can be large (more than 30000 observations) and I would ideally like something
For instance: if h = [1,4,18,22] and current t(i) translates to 7h21m56s (inside), it will be set in partition ' d2', if t(i) translates to 22h12m57s (thus outside the interval) in partition ' d1' and so on.
I made an utterly complicated function long time ago that doesn't seem to work. I am thus looking for something simpler and accurate.
My pseudo solution was:
function [d1, d2] = Create_TimeClasses(t, timeStamp, h)
%Create time classes (millisecond precision):
t0 = datenum(timeStamp);
%Reconstruct date vector:
k=1; l=1;
formatOut = 'HH:MM:SS.FFF';
ted = t0;
for i=2:size(t,2)
MM = floor(t(i));
ss = t(i)-MM;
SS = floor(ss*100); %2-digits seconds;
FFF = round((ss*100-floor(ss*100))*1000); %3-digits milliseconds precision.
%recreate the string: format: HH:MM:SS.FFF (FFF milliseconds) to take
%into account the side effects:
S = strcat('0:',num2str(MM), ':', num2str(SS), '.', num2str(FFF));
Str = datestr(S,formatOut); %String should now be ok
%Then gather the time and extract the number of milliseconds:
[~,~,~,hours,minutes,seconds] = datevec(Str, formatOut);
mSt = round(1000*(3600*hours + 60*minutes + seconds)); %milliseconds
%add to date
ted = addtodate(ted, mSt, 'millisecond');
aaa = datestr(ted, formatOut);
hed = str2double(aaa(1:2)); %hours
med = str2double(aaa(4:5)); %minutes
sed = str2double(aaa(7:8)); %seconds
%Correct for additional seconds:
if(sed/0.6 >= 1)
med = med+1;
end
hed = hed + mod(med/60, 24) + sed;
%Interesting activity time zone?
if(hed >= h(1) && hed <= h(2) || hed >= h(3) && hed <= h(4))
d1(k) = i; %yes
k=k+1;
else %non-activity time zone:
d2(l) = i;
l=l+1;
end
end
Thank you

Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!