How to import an excel file and split a column
11 visualizzazioni (ultimi 30 giorni)
Daphne PARLIARI il 19 Nov 2020
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 il 19 Nov 2020
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))
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 = 
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