0

I have two datetime variables that appear to be the same (even using format long), but matlab says they are not equal: Any idea what's going on here? I discovered this because the setxor function told me these values were mutually exclusive.

K>> T1(1)
ans = 
  datetime
   24-Aug-2020 18:00:01.730
K>> T2(2)
ans = 
  datetime
   24-Aug-2020 18:00:01.730
K>> datenum(T1(1))
ans =
     7.380277500200346e+05
K>> datenum(T2(2))
ans =
     7.380277500200346e+05
K>> isequal(T2(2),T1(1))
ans =
  logical
   0
  • 3
    Subtract one from the other and look at the difference, it's likely non-zero but you can't see it at the display precision. Possibly related: [why is 24.0000 not equal to 24.0000 in MATLAB](https://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab). You could `dateshift` to the nearest `'second'` and redo the comparison, or round the `datenum` value to some desired precision – Wolfie Apr 01 '21 at 16:09

1 Answers1

0

try

fprintf('%0X',typecast(datenum(T1(1)),'uint8'))
fprintf('%0X',typecast(datenum(T2(2)),'uint8'))

I suppose you should see difference in hex values

FangQ
  • 1,444
  • 10
  • 18