Parsing variable in table
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have a 3x1 table, with one variable, timestamp:
timestamp
2021-02-01 09:00:00
2021-02-01 09:01:00
2021-02-01 09:02:00
How can I parse this to create a 3x2 table, with two variables, date and time:
date time
2021-02-01 09:00:00
2021-02-01 09:01:00
2021-02-01 09:02:00
Any help would be appreciated!
IP
댓글 수: 2
Stephen23
2022년 11월 17일
편집: Stephen23
2022년 11월 17일
Note that changing the FORMAT does not changes the actual date/time values stored in the DATETIME object, it only changes how the DATETIME object looks when displayed or converted to text.
If you actually want to have the data consist only of the date and time values separately, then use DATESHIFT and TIMEOFDAY.
채택된 답변
Star Strider
2022년 11월 17일
편집: Star Strider
2022년 11월 17일
Try something like this —
T1 = table(datetime(['2021-02-01 09:00:00'
'2021-02-01 09:01:00'
'2021-02-01 09:02:00']), 'VariableNames',{'timestamp'})
date = T1.timestamp;
time = T1.timestamp;
date.Format = 'yyyy-MM-dd';
time.Format = 'HH:mm:ss';
T1 = addvars(T1,date,time);
T1 = removevars(T1,'timestamp')
There may also be other ways to do this.
EDIT — (17 Nov 2022 at 13:16)
I was not certain what you wanted.
Try this —
T1 = table(datetime(['2021-02-01 09:00:00'
'2021-02-01 09:01:00'
'2021-02-01 09:02:00']), 'VariableNames',{'timestamp'})
[y,m,d] = ymd(T1.timestamp); % Year, Month, Day Only
date = datetime([y,m,d]); % Convert Back To 'datetime'
time = timeofday(T1.timestamp); % Time Of Day Only
T1 = addvars(T1,date,time);
T1 = removevars(T1,'timestamp')
.
댓글 수: 4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!