Finding time difference that meet criteria

Hi guys
I need to compare two columns of data with each other. They are all in time format 00:00:00. I need to group them groups of two which are 20 seconds apart from each other and put the ones meeting the criteria in separate column. it could be 20 seconds before or after each other.
As an example, these consider two columns A and B columns. for example, the first row meets the criteria because it has 2 seconds difference in time which is less than 20.
I would appreciate any help. Thanks in advance!
A B
05:49:13 05:49:15
05:52:41 05:52:42
08:39:43 09:20:44
09:35:52 09:35:52
09:58:14 09:58:27
10:00:11 10:00:02
10:16:48 10:16:41
12:20:08 12:20:08
12:37:41 12:37:53
12:41:09 12:40:54
12:46:20 12:46:32
12:48:18 12:48:19

댓글 수: 2

jonas
jonas 2020년 7월 8일
identifying those pairs is trivial, but what exactly do you mean by putting them in separate columns? Could you just delete those which do not meet the criterion?
ALDO
ALDO 2020년 7월 8일
Thank you for your comment. yes deleting them could also work. but I need both the ones that meet critera and the ones that dont. I am new to using datetime so I do not know how to compare them.

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

답변 (1개)

jonas
jonas 2020년 7월 8일

0 개 추천

First make sure your data is in duration format.
%making up some data
t1 = (hours(10):hours(2):hours(24))';
t2 = t1 + rand(numel(t1),1).*seconds(40);
t = [t1,t2];
t.Format = 'hh:mm:ss';
%find time difference less than 20 s
id = abs(t1-t2)<seconds(20);
% remove pairs not meeting criterion
t(~id,:) = []

댓글 수: 3

ALDO
ALDO 2020년 7월 8일
Thank you for your answer. I should have mentioned this before but the arrays are not the same length. I got the following error
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
jonas
jonas 2020년 7월 9일
Okay, better provide some real data then. Can there for example be multiple matches in B to one element in A?
ALDO
ALDO 2020년 8월 1일
Hi! I appologize for the delay is my responce. Yes there could be multiple matches for B to one element in A. I will provide real data as soon as I have access to it! Thanks again!

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

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

질문:

2020년 7월 8일

댓글:

2020년 8월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by