table2timetable
Convert table to timetable
Syntax
Description
converts the input table to a timetable. The first datetime or duration variable in
TT
= table2timetable(T
)T
becomes the vector of row times of TT
.
The remaining variables of T
become the variables of
TT
.
If
T
is anM
-by-N
table without row names, thenTT
is anM
-by-(N-1)
timetable.If
T
is anM
-by-N
table with row names, thentable2timetable
assigns the row names ofT
to a variable ofTT
. As a result,TT
is anM
-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, use the readtimetable
function.
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 or index of
any variable in T
that contains datetime or duration values. The
remaining variables of T
become the variables of
TT
.
Examples
Input Arguments
Output Arguments
Tips
In certain cases, you can call
table2timetable
with a syntax that specifies a regular time step between row times, and yettable2timetable
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
datetime
values that are leap seconds. This table specifies the dates, times, and time steps that can produce irregular results 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 datetime
value occurring between 1:00 a.m. and 2:00 a.m. on a day shifting from DST to standard time (when such values have a time zone that observes DST).Number of calendar days or months. Any
datetime
value that is a leap second (when the time zone for such values is theUTCLeapSeconds
time zone). For the list of leap seconds, seeleapseconds
.Time step specified in any calendar unit (days, weeks, months, quarters, or years).