WHY DATE CANNOT TRANSFER FROM EXCEL TO MATLAB BY XLSREAD?

3 views (last 30 days)
Hello everyone,
To the right sight in the photo is my excell origin and to your left sight is my code (of xlsread) to transfer the data from column A to D. However, the result was just from column B to D! I changed to use readtable and the notice was: "Unable to determine the format of the DATETIME data, try adding a format to the DATETIME specifier".
Could you please help me? I have tried numerous times and still unsucced, I don't know how to fix this problem.
Thank you.
qq.png
  2 Comments
WHISKY Chen
WHISKY Chen on 25 Mar 2019
Edited: WHISKY Chen on 25 Mar 2019
Excuse me, could you please express more? Sorry I haven't imagined clearly. Thank you

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 23 Mar 2019
If you have R2013b or later, use the readtable (link) function. It should automatically convert the Excel dates to MATLAB dates.
  4 Comments
WHISKY Chen
WHISKY Chen on 28 Mar 2019
Really really thank you!
Based on your help, I can run it successfully! Thank you thank you!

Sign in to comment.

More Answers (1)

Peter Perkins
Peter Perkins on 25 Mar 2019
As SS says, in recent versions of MATLAB, readtable should give you a table with a datetime and a duration for those columns in your spreadsheet. If readtable does not do that, you are either using a version of MATLAB prior to that behavior (R2018a, IIRC), or your spreadsheet is not formatted properly. It's impossioble to tell because you have provided only screenshots.
In any case, use readtable. If the table contains text, convert to datetime and duration. Probably something like
T.DateTime = datetime(T.Date) + duration(T.Time);
The datetime conversion should work all the way back to R2014, the duration converstion is newer, but you can substitute text2duration form the File Exchange.
  1 Comment
WHISKY Chen
WHISKY Chen on 28 Mar 2019
Oh so thank you. The Datetime can also use in R2018, thank you!
The text2duration I haven't known before, let me try... thank you again!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!