Create a matrix with columns of both datetime and double format
조회 수: 38 (최근 30일)
이전 댓글 표시
I want to create a matrix with these vectors:
a = [21-Mar-2021 07:44
21-Mar-2021 17:35
22-Mar-2021 07:48
22-Mar-2021 17:46
23-Mar-2021 07:49
23-Mar-2021 17:48];
b = [21
23
24
26
27
29];
When I try the following sentence, MATLAB gives me an error:
c=[a,b];
Error using datetime/horzcat (line 1335)
All inputs must be datetimes or date/time character vectors or date/time strings.
I don't know how to merge both columns in a single matrix. Can you help me?
댓글 수: 0
채택된 답변
Mario Malic
2021년 5월 2일
Hi,
Use a cell array or a table to do so.
% Using cell array
{datetime('today'), 5}
% Using table
dt = datetime('now');
num = 5;
table(dt, num)
댓글 수: 1
Steven Lord
2021년 5월 2일
A table array would work, but a timetable array has some functionality for working with the date and time data above and beyond what you can do with a table.
dt = datetime('now');
num = 5;
tt = timetable(dt, num)
추가 답변 (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!