Convert serial date to string in a table so that table2timetable can be used
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to import an excel sheet and convert it into a time table. Currently the dates are in serial excel format.
From what I understand table2timetable only accepts dates in string or vector format. How do I convert the format of a entire column to date string?
tbl = readtable('data.xlsx');
%convert first row of table to string date
TT = table2timetable(tbl)
Some example data from the read table:
Date Data1 Data2
_____ _________________ ________________
43373.53 275.54 43.516
43373.54 292 43.639
43373.55 215.67 43.443
Thanks!
1 个评论
Peter Perkins
2019-2-13
Wlter's answer is correct, but it's worth noting that in recent versions of MATLAB, assuming the data are stored appropriately in the spreadsheet, readtable will create those datetimes automatically. And in slightly earlier versions, you can tell readtable to create datetimes. It is possible, however, for the data in the spreadsheet to be stored in a way that foils readtable.
采纳的回答
Walter Roberson
2019-2-10
TT = table2timetable(tbl(:,2:end), 'RowTimes', datetime(tbl{:,1}, 'convertfrom', 'excel'));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!