From date and time in different columns to datetime

조회 수: 26(최근 30일)
Hey, I have an array with date (yyyy-mm-dd) in one columns and time (hh:mm:ss) in another like this:
2017-09-29 21:00:00
2017-09-29 22:00:00
2017-09-29 23:00:00
2017-09-30 00:00:00
2017-09-30 01:00:00
2017-09-30 02:00:00
2017-09-30 03:00:00
How can I make this array into a datetime array?
  댓글 수: 1
Andrei Bobrov
Andrei Bobrov 2018년 3월 20일
편집: Andrei Bobrov 2018년 3월 20일
Please attach an example of your data (as mat-file) so that we know what type of data you are using.

댓글을 달려면 로그인하십시오.

채택된 답변

Akira Agata
Akira Agata 2018년 3월 20일
Assuming your data is stored in CSV file like the attached, readtable function automatically recognize that 1st and 2nd column are datetime and duration. So, the following can make the datetime vector you want.
T = readtable('data1.csv');
time = T{:,1}+T{:,2};
  댓글 수: 7
Peter Perkins
Peter Perkins 2020년 7월 28일
It's described in the examples here:
If a recent version of readtable (NOT xlsread) can't automatically identify date columns, then there's something in the spreadsheet that's not "right". The cells in the spreadsheet may not be formatted as dates. There may be a mix of text and other things. Hard to say for sure, but recent versions of readtable are pretty good at detecting dates.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Andrei Bobrov
Andrei Bobrov 2018년 3월 20일
편집: Andrei Bobrov 2018년 3월 20일
datetime('2017-09-29') + hours(21:27)'

Community Treasure Hunt

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

Start Hunting!

Translated by