How to import an excel file and split a column
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Daphne PARLIARI
le 19 Nov 2020
Commenté : Daphne PARLIARI
le 24 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!
0 commentaires
Réponse acceptée
Peter Perkins
le 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))
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!