Effacer les filtres
Effacer les filtres

how to compare 2 different time in matlab

17 vues (au cours des 30 derniers jours)
saharsahar
saharsahar le 23 Juin 2013
Hi all,
I have 2 different time, 21:45:53 and 21:04:22 , regardless of date( we assume both are in same date), How I can figure out which one is earlier than the other?
I am using
[first_val]=[datenum(time_ir(1,:),'HH:MM:SS'),datenum(time_e_rad(1,:),'HH:MM:SS')];
[early_first,index]=min(first_val);
where time_e_rad(1,:)= 21:45:53 and time_ir(1,:)= 21:04:22
while datenum of both gives me a same number. I understand datenum is using to compare dates and not times! is there anyway to compare two times?
Thanks

Réponse acceptée

per isakson
per isakson le 23 Juin 2013
Modifié(e) : per isakson le 23 Juin 2013
I have not reproduced your: while datenum of both gives me a same number.
Should work:
sdn1 = datenum( '21:45:53', 'HH:MM:SS' );
sdn2 = datenum( '21:04:22', 'HH:MM:SS' );
format long
sdn1
sdn2
returns
sdn1 =
7.352359068634260e+05
sdn2 =
7.352358780324074e+05
they differ
>> sdn1 > sdn2
ans =
1

Plus de réponses (2)

Image Analyst
Image Analyst le 23 Juin 2013
They are not the same number. The bigger number is the later time:
serialDate1 = datenum('21:45:53')
serialDate2 = datenum('21:04:22')
serialDate1 =
735235.906863426
serialDate2 =
735235.878032407

saharsahar
saharsahar le 23 Juin 2013
Thank u very much. I got the point. Appreciated !

Catégories

En savoir plus sur Time Series Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by