Grouping based upon differences in time, with some small scatter

조회 수: 3 (최근 30일)
Hello!
We have an application to analyze digital signals from several events on separate instruments. There is a time stamp in each record. There can be a small offset in the time recorded (<30 seconds) for a single event on separate instruments. For example:
{[27-Aug-2020 12:30:13]}
{[27-Aug-2020 12:39:23]}
{[27-Aug-2020 12:47:46]}
{[27-Aug-2020 12:30:15]}
{[27-Aug-2020 12:39:25]}
{[27-Aug-2020 12:47:48]}
{[27-Aug-2020 12:30:18]}
{[27-Aug-2020 12:39:28]}
So there are three events (~12:30, ~12:39, ~12:47), the first two recorded on three instruments, the last event on only two. Since the delay may be up to 30 seconds, ignoring the seconds isn't an option.
In practice there may be tens of events and a hundred instruments, so grouping this is a bit of a pain. I can use datenum() and then seconds() to get whether the difference is less than 30 seconds, but kind of hung up on what to do next.
Any suggestions?
Thanks!
Doug Anderson
  댓글 수: 2
Douglas Anderson
Douglas Anderson 2021년 2월 16일
A thought...
findgroups() looks like it might be helpful, but not sure how to make a group +- 30 seconds
Douglas Anderson
Douglas Anderson 2021년 2월 17일
Or maybe use of uniquetol()??

댓글을 달려면 로그인하십시오.

채택된 답변

Duncan Po
Duncan Po 2021년 2월 18일
One way to do this is to use isbetween in a for loop, and then unique(, 'rows') to find the groups:
t = datetime({'27-Aug-2020 12:30:13',
'27-Aug-2020 12:39:23',
'27-Aug-2020 12:47:46',
'27-Aug-2020 12:30:15',
'27-Aug-2020 12:39:25',
'27-Aug-2020 12:47:48',
'27-Aug-2020 12:30:18',
'27-Aug-2020 12:39:28'}); % put the data in a datetime
tmax = t + seconds(30); % determine the 30s offsets from each element
tmin = t - seconds(30);
for i = 1:length(t) % loop through each element
y(i,:) = isbetween(t, tmin(i), tmax(i));
end
yy = unique(y, 'rows') % each row is a logical vector indicating which element belongs to the same group

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by