Convert table to timetable
converts
the table TT
= table2timetable(T
)T
to a timetable. The first datetime
or duration variable in T
becomes the vector of
row times of TT
. The remaining variables of T
become
the variables of TT
.
If T
is an M
-by-N
table
without row names, then TT
is an M
-by-(N-1)
timetable.
If T
is an M
-by-N
table
with row names, then table2timetable
assigns the
row names of T
to a variable of TT
.
As a result, TT
is an M
-by-N
timetable.
For more information on creating and using timetables, see Timetables.
To create a timetable from data in a text or spreadsheet file,
first use the readtable
function
to read the data to a table. Then convert the table to a timetable
with table2timetable
.
assigns the table variable TT
= table2timetable(T
,'RowTimes',timeVarName
)timeVarName
as the vector of row times
of the output timetable. timeVarName
can be the name of any
variable in T
that contains datetime or duration values. The
remaining variables of T
become the variables of
TT
.
In certain cases, you can call table2timetable
with a syntax
that specifies a regular time step between row times, and yet
table2timetable
returns an irregular timetable. This result
occurs when you specify the time step using a calendar unit of time and there is
a row time that introduces an irregular step. For example, if you create a
timetable with a time step of one calendar month, starting on January 31, 2019,
then it is irregular with respect to months.
stime = datetime(2019,1,31); tstep = calmonths(1); T = table([1:3]'); TT = table2timetable(T,'TimeStep',tstep,'StartTime',stime)
TT = 3×1 timetable Time Var1 ___________ ____ 31-Jan-2019 1 28-Feb-2019 2 31-Mar-2019 3
There are other cases where irregularities are due to shifts from Daylight Saving Time (DST) or to row times that are leap seconds. This table specifies the row time values and time steps that can produce irregular timetables unexpectedly.
Row Time Value | Time Step |
---|---|
Start time specified as the 29th, 30th, or 31st day of the month. | Number of calendar months or quarters. |
Start time specified as February 29. | Number of calendar years. |
Any row time occurring between 1:00 a.m. and 2:00 a.m. on a day shifting from DST to standard time (when row times are specified as datetime values whose time zone observes DST). | Number of calendar days or months. |
Any row time that is a leap second (when row times are specified as
datetime values whose time zone is the | Time step specified in any calendar unit (days, weeks, months, quarters, or years). |
array2timetable
| isvarname
| summary
| timetable
| uitable