Merge two columns of a cell array into one

조회 수: 35 (최근 30일)
BOB
BOB 2018년 2월 23일
댓글: Giuseppe Degan Di Dieco 2021년 4월 26일
Hi,
I have two columns of cell values:
I want to merge these two columns to produce one third column in the format yyyy-mm-dd hh-mm-ss.
Thanks for any help!

답변 (1개)

KSSV
KSSV 2018년 2월 23일
c1 = {'2104-04-14'; '2014-04-14'} ;
c2 = {'13:17:08'; '13:16:45'} ;
datetime(strcat(c1,{' '},c2))
  댓글 수: 8
Jan
Jan 2018년 2월 24일
@John BG: Bob said "Thank you!" already, which sounds like the problem was solved. Then datetime works already. Maybe you did not understand, how datetime stores its data internally, but it does not matter what you set as display format. A calculation like "£301.- (YYYY-MM-DD)" is nonsense. If you need the value of a datetime object, you would e.g. use:
301 - day(B(1))
and for the output of day(B) it does not matter, if the date is displayed as YYYY-MM-DD or DD-MM-YYYY. This is the idea of datetime compared to the old serial date numbers or date vectors, where the display and the meaning of the dates and times were related.
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021년 4월 26일
Dear KSSV, your solution it really helped me in concatenating two cell arrays of character vectors into one cell array. Also, the cell arrays belonged to a data table. Thank you.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by