Substract all elements from one vector minus all elements from other vector

2 Ansichten (letzte 30 Tage)
Alejandro Sanz am 23 Mai 2021
Beantwortet: Bandar am 24 Mai 2021
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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Bandar am 24 Mai 2021
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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Kategorien

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

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by