Grouping based upon differences in time, with some small scatter

3 ビュー (過去 30 日間)
Douglas Anderson
Douglas Anderson 2021 年 2 月 16 日
コメント済み: Douglas Anderson 2021 年 2 月 19 日
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 Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by