MATLAB: How to subtract time in million second precision

differencetime

I have 2 table arrays of date(1st column) and time (2nd column) and I would like to check the time difference. Could you kindly advise?
My second values are in million second precision, e.g., 11:34:08.471810 and 11.34.06.471840 (as attached picture) How may I go about getting the time difference? I understand some of MATLAB function has limitation till millisecond. Have tried a few stuff (datevec, datenum, etc.) but not getting the precise results.
Thank you.

Best Answer

The picture you attached shows 5 decimal places of seconds. That is right at the boundary of accuracy possible with datenum; datenum cannot actually represent down to 10^-5 seconds, but it can represent to 1.0058E-5 seconds -- at least for modern times.
Your question, though, lists down to 10^-6 seconds, which definitely more accurate than datenum can justify.
My advice would be to use datetime() instead of datenum().
in_datestr = strcat(tab.carlog_date_final, {' '}, tab.carlog_time_final);
in_dates = datetime(in_datestr,'InputFormat', 'd-M-yyyy hh:mm:ss.SSSSS', 'Format', 'yyyy/MM/dd hh:mm:ss.SSSSS');
After that you can
seconds(diff(in_dates)) * 10^6
or as appropriate for the time scale you wish to pay attention to.
(Note: you do not actually need the 'Format' option for the datetime() call if you are only looking at the differences -- but it is nice to be able to debug that the milliseconds have been converted properly.)