Effacer les filtres
Effacer les filtres

Grouping based upon differences in time, with some small scatter

4 vues (au cours des 30 derniers jours)
Douglas Anderson
Douglas Anderson le 16 Fév 2021
Commenté : Douglas Anderson le 19 Fév 2021
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 commentaires
Douglas Anderson
Douglas Anderson le 16 Fév 2021
A thought...
findgroups() looks like it might be helpful, but not sure how to make a group +- 30 seconds
Douglas Anderson
Douglas Anderson le 17 Fév 2021
Or maybe use of uniquetol()??

Connectez-vous pour commenter.

Réponse acceptée

Duncan Po
Duncan Po le 18 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by