Substract all elements from one vector minus all elements from other vector
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I have two vectors of dates. One vector has 3 dates, for example 14/08/2020 16:32, 15/08/2020 19:26, 18/08/2020 16:28 and other vector has 6 dates. I want to see which dates of those two vectors have the condition that the difference between dates of vector 1 - date of vector 2 is 2 minutes or less.
The 2 vectors have different number of dates, and I want to substract all the dates and only remain with the dates which differ in less than 2 minutes.
댓글 수: 0
답변 (1개)
Bandar
2021년 5월 24일
t1 = datetime(2013,11,5,23,2,0);
t2 = datetime(2013,10,5,23,3,0);
t3 = datetime(2013,10,5,23,1,0);
vec1 = [t1 t2 t3];
t4 = datetime(2014,11,5,23,0,0);
t5 = datetime(2013,10,5,23,1,0);
t6 = datetime(2003,10,5,23,1,0);
t7 = datetime(2013,11,5,23,0,0);
t8 = datetime(2013,10,5,23,1,0);
t9 = datetime(2013,10,5,23,1,0);
vec2=[t3 t4 t5 t6 t7 t8 t9];
for i = 1:numel(vec1)
for j=1:numel(vec2)
t = vec1(i) - vec2(j);
[h,m,s] = hms(t);
if (h == 0) && (m <= 2)
vec1(i)
vec2(j)
h
m
end
end
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!