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!

采纳的回答

Peter Perkins
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
  1 个评论
Daphne PARLIARI
Daphne PARLIARI 2020-11-24
Thank you for your answer!
I want to split the column because the rest of my script is based on this logic, therefore I thought it would be easier to just split the column and proceed from there...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by