How to read a spreadsheet with date and time in Matlab?

Asked

Viewed 1,273 times

2

How do I import data from an excel spreadsheet that contains date and time (e.g.: 10/22:45:10) in Matlab?

  • Hello! welcome to Sopt. To import an excel file you can use the function xlsread.

1 answer

2

Recommend:

  1. use the xlsread command,
  2. or convert the file to csv format and then use the csvread command,
  3. or if none of these solutions please you you can use the readtable.

For the latter, I will show how to import an excel file containing dates to a table in Matlab. Be the hypothetical.xls weight file with the following data.

   Data        Peso
___________    ______

31-Oct-1996    174.8 
29-Nov-1996    179.3 
30-Dec-1996    190.4 
31-Jan-1997    185.7 

Now do the following.

T = readtable('weight.xls')

T =

    Data        Peso
____________    ______

'10/31/1996'    174.8 
'11/29/1996'    179.3 
'12/30/1996'    190.4 
'1/31/1997'     185.7 

In windows, with Excel, the Data variable is a string field of the Cell array. To convert it just do:

T.Data = datetime(T.Data,'Inputformat','MM/dd/yyyy')

T =

   Data        Peso
___________    ______

31-Oct-1996    174.8 
29-Nov-1996    179.3 
30-Dec-1996    190.4 
31-Jan-1997    185.7 

This example was originally put on when-to-Convert-Dates-from-excel-files

  • Thank you for the reply!

  • Imagine, no need to thank. We’re here for this very.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.