使用 OutputType 和 RowTimes 名称-值对组来使 tabulartextDatastore 返回时间表,而不是表。
为 outages.csv 创建一个数据存储。将 'OutputType' 名称-值对组指定为 'timetable'。
ttds = tabularTextDatastore('outages.csv','OutputType','timetable');
preview(ttds)
ans=8×5 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' }
2003-06-18 02:49 {'West' } 0 0 2003-06-18 10:54 {'attack' }
2004-06-20 14:39 {'West' } 231.29 NaN 2004-06-20 19:16 {'equipment fault'}
2002-06-06 19:28 {'West' } 311.86 NaN 2002-06-07 00:51 {'equipment fault'}
如果您没有同时指定 'RowTimes',tabularTextDatastore 将使用第一个日期时间或持续时间变量作为行时间。在本例中,将 OutageTime 变量用于行时间。
指定 'RowTimes' 选项以使用恢复时间(RestorationTime 变量)作为行时间,而不是使用停电时间。
ttds = tabularTextDatastore('outages.csv','OutputType','timetable','RowTimes','RestorationTime');
preview(ttds)
ans=8×5 timetable
RestorationTime Region OutageTime Loss Customers Cause
________________ _____________ ________________ ______ __________ ___________________
2002-02-07 16:50 {'SouthWest'} 2002-02-01 12:18 458.98 1.8202e+06 {'winter storm' }
NaT {'SouthEast'} 2003-01-23 00:49 530.14 2.1204e+05 {'winter storm' }
2003-02-17 08:14 {'SouthEast'} 2003-02-07 21:15 289.4 1.4294e+05 {'winter storm' }
2004-04-06 06:10 {'West' } 2004-04-06 05:44 434.81 3.4037e+05 {'equipment fault'}
2002-03-18 23:23 {'MidWest' } 2002-03-16 06:18 186.44 2.1275e+05 {'severe storm' }
2003-06-18 10:54 {'West' } 2003-06-18 02:49 0 0 {'attack' }
2004-06-20 19:16 {'West' } 2004-06-20 14:39 231.29 NaN {'equipment fault'}
2002-06-07 00:51 {'West' } 2002-06-06 19:28 311.86 NaN {'equipment fault'}