Select Timetable Data by Row Time and Variable Type
A timetable is a type of table that associates a time with each row. You can subscript into
a timetable to select subsets of its data in a number of different ways. To select timetable
rows with row times that fall within a given time range, specify the time range using the
timerange function. Since a timetable is a table, you can index on rows and variables
using either smooth parentheses or curly braces. You can index on specific row times, or
select rows with row times that match specified times within a tolerance you set using the
withtol function. You can also subscript into a table or timetable to select all the
variables that match a type you specify with the vartype function. Finally, extract data
from a timetable into a matrix using the Variables property.
Create Timetable from File
Create a timetable from the sample file outages.csv, containing data representing
electric utility outages in the United States. Read the table from the file with the
readtable function. Convert T.Cause and T.Region into categorical arrays. Then
convert the table to a timetable using the table2timetable function. Display the first
five rows of the timetable. TT is a timetable containing outage data from February 2002 to
January 2014.
T = readtable('outages.csv');
T.Cause = categorical(T.Cause);
T.Region = categorical(T.Region);
TT = table2timetable(T);
TT(1:5,:)
ans=5×6 timetable
OutageTime Region Loss Customers RestorationTime Cause
________________ _________ ______ __________ ________________ _______________
2002-02-01 12:18 SouthWest 458.98 1.8202e+06 2002-02-07 16:50 winter storm
2003-01-23 00:49 SouthEast 530.14 2.1204e+05 NaT winter storm
2003-02-07 21:15 SouthEast 289.4 1.4294e+05 2003-02-17 08:14 winter storm
2004-04-06 05:44 West 434.81 3.4037e+05 2004-04-06 06:10 equipment fault
2002-03-16 06:18 MidWest 186.44 2.1275e+05 2002-03-18 23:23 severe storm
Summarize Timetable and Access Row Times
Display a summary of TT. It is a timetable that contains 1468 rows and five variables.
summary(TT)
10 Timetables