Info

This question is closed. Reopen it to edit or answer.

Discrepancies in how time is shown in MATLAB vs. Excel.

1 view (last 30 days)
I'm experiencing an issue when using datestr to convert a vector containing date/time information from an excel xlsx file into a date/time string. I'm importing the information using the import button on the MATLAB GUI, and I'm working with MATLAB 2014a.
The command is working fine and appears correct at first, but there is a difference in the times displayed in excel, and the times displayed in MATLAB. It's not uniform across all data points, but some are out by a single second. (See below). I need the temporal resolution to be accurate (as accurate as can when working to seconds) so being off by a second is not really acceptable.
Examples:
MATLAB: '093221' '093254' '093448' '093526' '093630' '093844'
Excel: '09:32:22' '09:32:55' '09:34:49' '09:35:27' '09:36:31' '09:38:44'
Can anyone offer any advice on what's going on? Is it a MATLAB version problem, an excel file problem? The serial number as I understand is a standardised thing, so I'm puzzled.
Thanks for your help in advance,
Joe
EDIT:
I've changed both files to display milliseconds, but the discrepancy still exists:
MATLAB: '093221902' '093254787' '093448616' '093526841' '093630663' '093844407'
EXCEL:
'09:32:22.000' '09:32:55.000' '09:34:48.616' '09:35:26.841' '09:36:30.663' '09:38:44.407'
  4 Comments
dpb
dpb on 11 Feb 2016
Good point re: the tool. Can't say I've ever used it; I'd suggest to OP to use xlsread on the row and compare results to content. I'd venture it'll agree.
Kirby Fears
Kirby Fears on 11 Feb 2016
Edited: Kirby Fears on 11 Feb 2016
I put your example date into cells A1:F1 of excel:
09:32:22.000,09:32:55.000,09:34:48.616,09:35:26.841,09:36:30.663,09:38:44.407
I read these into Matlab using the Import tool and imported the data as "Numeric Matrix".
Inspecting the datevector produced from datevec(importedDates), the values are exactly the same as Excel down to the millisecond. Also using datestr returns the right values to second precision:
datestr(importedDates,'HHMMSS')
ans =
093222
093255
093448
093526
093630
093844
This is using Matlab 2015a and Excel 2010.

Answers (0)

Community Treasure Hunt

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

Start Hunting!