MATLAB: Grouping time stamp data into intervals

datadata analysisfinding continuous dataintervaltime intervalstime stamps

I have a set of time stamps with a sampling frequency of 1000 (samples every .001). I want to take any time stamps that are continuous for more than 10 seconds (10,000 data points) to be taken as an interval. Is this possible? I attached a example data of time stamps.

Best Answer

I'm a little bit confused as of what you want to do with those segments, but this code should find them for you. I'm not entirely sure it works, but the plot looks promising. As, dsb already pointed out, it would be a good idea to provide a smaller example.
t = times_1;
dt = [0 diff(t)];
% Group segment having a time diff less than 0.001 (+tol)
mask=dt < 0.0011;
d(mask) = 0;
d(~mask) = 1;
d = cumsum(d);
% find trailing integers
[counts,val] = histcounts(d,'binwidth',1)
% find groups longer than 10 s
v = val((counts/10000) > 10);
sv = zeros(size(d));
for j = 1:length(v)
sv = sv + (d == v(j));
end
sv = logical(sv);
sv(~mask)=0;
% plot
plot(sv,'b','linewidth',2);hold on
plot(d)