How to import an excel file and split a column

조회 수: 12 (최근 30일)
Daphne PARLIARI
Daphne PARLIARI 2020년 11월 19일
댓글: Daphne PARLIARI 2020년 11월 24일
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에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by