Importing excel time data

I am trying to read an excel file containg the date and time in the format "dd/mm/yyyy HH:MM:SS". (The excel contains eight columns [Date, Time, data1, data2, data3,data4,data5,data6,data7,data8])
I read the excel file with the code
opts = detectImportOptions("LW.xlsx");
T = readtable("LW.xlsx",opts)
T = 240×8 table
Date Time T DH DN E GH Z _____ ________ ____ ___ ___ __ ___ ___ 39083 0 22.7 0 0 0 0 155 39083 0.041667 22.5 0 0 0 0 144 39083 0.083333 22 0 0 0 0 132 39083 0.125 21.8 0 0 0 0 118 39083 0.16667 21.6 0 0 0 0 104 39083 0.20833 21.7 7 0 0 7 91 39083 0.25 22.2 81 59 2 84 77 39083 0.29167 23.6 183 205 7 190 64 39083 0.33333 25 311 319 0 311 51 39083 0.375 26 457 324 0 457 39 39083 0.41667 27 536 346 0 536 31 39083 0.45833 27.6 566 362 0 566 28 39083 0.5 27.6 506 276 0 506 32 39083 0.54167 27.5 361 242 0 361 41 39083 0.58333 27.2 313 210 0 313 53 39083 0.625 26.6 209 173 12 221 65
T = table2timetable(T)
Error using table2timetable
Input table must contain datetime or duration vector for row times.
Time =datetime(T.Time, "ConverFrom", "datenum", "Format", "HH:mm:ss");
Date =datetime(T.Date, "ConverFrom", "datenum", "Format", "dd/MM/yyyy");
TD = mergevars(T,{"Date","Time"},...
"NewVariableName","DateTime", "MergeAsTable",true);
I get error message when I try table2timetable and also when I try to merge Time and Date
How do I fix this please.

1 Comment

hi
it would be helpfull to share your excel file as well

Sign in to comment.

Answers (1)

Luca Ferro
Luca Ferro on 24 May 2023

4 Comments

[Sig, TStr, Raw] = xlsread('LW.xlsx',1,'A1:B240');
Error using xlsread
Unable to open file 'LW.xlsx'.
File '/users/mss.system.e6SoNr/LW.xlsx' not found.
I get this error message when I use the line code
make sure that the LW.xlsx file is on matlab path
The file is on path
make sure you have read / write permission on your path
are you sure you are not working in a windows protected path ?

Sign in to comment.

Products

Release

R2023a

Commented:

on 25 May 2023

Community Treasure Hunt

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

Start Hunting!