Importing dates from an Excel file using Import Data Function
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
In the new version of Matlab (2014b) there no longer seems to be the option to replace dates from an excel file with their matlab number. Instead the Import Data function considers them unimportable and defaults to replacing them with NaN. I can't seem to find any option that allows me to import the dates as Matlab number (as part of a Numeric Matrix). Does anyone know how to do this?
0 Kommentare
Antworten (2)
dpb
am 26 Mär. 2015
I don't have past R2012b so can't test but current doc surely doesn't say anything about it...then again, not sure if earlier versions did or not, either, or whether it was just behavior. Anyway, seems like a regression, agreed.
But, doc does indicate that readtable does the conversion automagically in the auxiliary section on Excel and Matlab dates. Failing that, it's not particularly difficult to use xlsread and then convert the date string cell; it's just an additional step.
0 Kommentare
Rob Jacobs
am 9 Apr. 2015
R2014b introduced new data types - datetime, duration and calendarDuration - for representing dates and times in MATLAB. These new objects are an improvement over using datenums for working with dates and times, so we wanted to facilitate their use as much as possible. To do so we integrated support for datetime into the Import Tool, and in the process we dropped support for datenum. Without support for datenum the dates in the Excel file are now ‘unimportable’.
The approach to take is to set the imported data type to “Table” or “Column vectors”. When you use either of these data types you can set the target type for these to datetime in the popup menu below the column variable name.
If you have existing code which requires the use of numeric datenums, you can:
- Import as Table or Column Vectors and convert datetimes to datenum by calling datenum on the datetime variable(s), or
- The Import Tool generated code will contain a commented section of code that when uncommented will change the datetime values into numeric datenum.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!