How to import an excel file and split a column
5 次查看(过去 30 天)
显示 更早的评论
Hello guys! I hope everyone is health and safe...
I would like to ask a question please:
I am trying to import some excel files like the one I have attached, with Import option of Matlab R2019a. I want the first column, which contains date ant time together, ti be imported as two separate columns, one with date and one with time.
Is there a way to do it using Import?
Thank you in advance!
0 个评论
采纳的回答
Peter Perkins
2020-11-19
The short answer is no. Your timestamps are stored in the spreadsheet as floating point numbers. But why do you need to split time and date during import?
Read in the data using readtable, then use the timeofday function on the datetime variable in your table to make a new time variable i nthe table, then subtract that from the date.
>> t = table(datetime(2020,19,1) + 5*days(rand(5,1)),rand(5,1))
t =
5×2 table
Var1 Var2
____________________ _______
02-Jul-2021 11:37:09 0.64467
03-Jul-2021 00:55:09 0.52366
03-Jul-2021 15:37:28 0.49436
04-Jul-2021 08:32:34 0.36744
03-Jul-2021 16:26:05 0.61592
>> t.Time = timeofday(t.Var1);
>> t.Date = t.Var1 - t.Time;
>> t.Var1 = []
t =
5×3 table
Var2 Time Date
_______ ________ ___________
0.64467 11:37:09 02-Jul-2021
0.52366 00:55:09 03-Jul-2021
0.49436 15:37:28 03-Jul-2021
0.36744 08:32:34 04-Jul-2021
0.61592 16:26:05 03-Jul-2021
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!