Grouping based upon differences in time, with some small scatter

3 Ansichten (letzte 30 Tage)
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 Kommentare
Douglas Anderson
Douglas Anderson am 16 Feb. 2021
A thought...
findgroups() looks like it might be helpful, but not sure how to make a group +- 30 seconds

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Duncan Po
Duncan Po am 18 Feb. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by