www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ConvertTableToTimetableExample.m
%% Convert Table to Timetable % Convert a table that contains dates and times to a timetable. % % Read power outage data from the file |outages.csv| to a table. The % table contains both outage and restoration times. T = readtable('outages.csv'); T(1:5,:) %% % Convert the table to a timetable. The first variable with times, % |OutageTime|, becomes the time vector of |TT|. TT = table2timetable(T); TT(1:5,:) %% % Index into |TT| using row times from its time vector. You can treat the % row times as labels that specify rows. TT('02/07/2003 21:15',:) %% % Calculate the duration of power outages. Use dot syntax to % extract the row times as a vector. TT.OutageDuration = TT.RestorationTime - TT.OutageTime; TT(1:5,:)