Removing part of a cell array

조회 수: 8 (최근 30일)
Brian Gregory
Brian Gregory 2021년 6월 16일
댓글: Walter Roberson 2021년 6월 16일
Hello.
I have a data table 1441x1 reading as a cell. The data in this cell is "06/15/2021 12:00 AM" and changes in time by the minute to make up the 1441x1 cell.
My goal is to be left with an array of only the times, as such "12:00" "12:01"... and so on. Any help is appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 16일
Why not just convert as-is ?
S = '06/15/2021 12:00 AM'
S = '06/15/2021 12:00 AM'
datetime(S, 'InputFormat', 'MM/dd/yyyy hh:mm a', 'Format', 'yyyy/MM/DD HH:mm')
ans = datetime
2021/06/166 00:00
Note the InputFormat uses hh, which is the code for 12-hour numbering format. The 'a' field accepts AM or PM and informs MATLAB of which 12 hour block.
The OutputFormat I coded to use HH which is the code for 24-hour numbering format.
  댓글 수: 3
Brian Gregory
Brian Gregory 2021년 6월 16일
Actually, I was able to get this to work using the different format yyyy-MM-dd which is the one I desired. Thanks!
Walter Roberson
Walter Roberson 2021년 6월 16일
opps yes DD should have been dd

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by