user1921722
user1921722

Reputation: 55

Time Comparison in MATLAB

I would like to compare a time string '09:12:00', within a given time interval ? Such as , T = '09:12:00';

if ( '03:00:00' < T < '05:00:00' ) end

Upvotes: 2

Views: 1671

Answers (2)

Stefano M
Stefano M

Reputation: 4809

Simply convert time strings to serial date number via datenum

if ( datenum('03:00:00') < datenum(T) & datenum(T) < datenum('05:00:00') ) end

Upvotes: 2

plesiv
plesiv

Reputation: 7028

I'm not aware of existence of standard Matlab function that would do C-style comparison, as these user written function do: lexcmp, strcmpc ...

It's not necessarily pretty, but you can do it with sort, strcmp and find:

T = '09:12:00';

S = sort({'03:00:00', T, '05:00:00'});
F = find(strcmp(T, S));
if (1 == length(F) && 2 == F(1))
    % if T is  between given limits...
end

Upvotes: 0

Related Questions