Importing dates from an Excel file using Import Data Function

조회 수: 2 (최근 30일)
Peter Vassallo
Peter Vassallo 2015년 3월 26일
답변: Rob Jacobs 2015년 4월 9일
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?

답변 (2개)

dpb
dpb 2015년 3월 26일
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.

Rob Jacobs
Rob Jacobs 2015년 4월 9일
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:
  1. Import as Table or Column Vectors and convert datetimes to datenum by calling datenum on the datetime variable(s), or
  2. The Import Tool generated code will contain a commented section of code that when uncommented will change the datetime values into numeric datenum.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by